Skip to content

Commit

Permalink
test: add basic coverage for document and window
Browse files Browse the repository at this point in the history
  • Loading branch information
buschtoens committed May 12, 2019
1 parent 9ac9430 commit 60d93e1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
33 changes: 27 additions & 6 deletions tests/integration/helpers/on-document-test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { render, click, resetOnerror } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Helper | on-document', function(hooks) {
setupRenderingTest(hooks);
hooks.afterEach(() => resetOnerror());

// Replace this with your real tests.
test('it renders', async function(assert) {
this.set('inputValue', '1234');
test('it basically works', async function(assert) {
assert.expect(6);

await render(hbs`{{on-document inputValue}}`);
this.someMethod = function(event) {
assert.ok(this instanceof HTMLDocument, 'this context is the document');
assert.ok(
event instanceof MouseEvent,
'first argument is a `MouseEvent`'
);
assert.strictEqual(
event.target.tagName,
'BUTTON',
'correct element tagName'
);
assert.dom(event.target).hasAttribute('data-foo', 'test-element');
};

assert.equal(this.element.textContent.trim(), '1234');
await render(hbs`
{{on-document "click" this.someMethod}}
<button type="button" data-foo="test-element"></button>
`);

assert.counts({ adds: 1, removes: 0 });

await click('button');

assert.counts({ adds: 1, removes: 0 });
});
});
33 changes: 27 additions & 6 deletions tests/integration/helpers/on-window-test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { render, click, resetOnerror } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Helper | on-window', function(hooks) {
setupRenderingTest(hooks);
hooks.afterEach(() => resetOnerror());

// Replace this with your real tests.
test('it renders', async function(assert) {
this.set('inputValue', '1234');
test('it basically works', async function(assert) {
assert.expect(6);

await render(hbs`{{on-window inputValue}}`);
this.someMethod = function(event) {
assert.ok(this instanceof Window, 'this context is the window');
assert.ok(
event instanceof MouseEvent,
'first argument is a `MouseEvent`'
);
assert.strictEqual(
event.target.tagName,
'BUTTON',
'correct element tagName'
);
assert.dom(event.target).hasAttribute('data-foo', 'test-element');
};

assert.equal(this.element.textContent.trim(), '1234');
await render(hbs`
{{on-window "click" this.someMethod}}
<button type="button" data-foo="test-element"></button>
`);

assert.counts({ adds: 1, removes: 0 });

await click('button');

assert.counts({ adds: 1, removes: 0 });
});
});

0 comments on commit 60d93e1

Please sign in to comment.