Skip to content

Commit

Permalink
Update tests per review suggestion
Browse files Browse the repository at this point in the history
Co-authored-by: Alex <[email protected]>
  • Loading branch information
didoo and alex-ju committed Apr 16, 2024
1 parent 694d05b commit a46238d
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions showcase/tests/integration/modifiers/hds-register-event-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,41 @@

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { click, render } from '@ember/test-helpers';
import { click, render, triggerEvent } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Modifier | hds-register-event', function (hooks) {
setupRenderingTest(hooks);

test('it calls the callback associated with the `click` event assigned via the modifier', async function (assert) {
let clicked;
this.set('onClick', () => (clicked = true));
test('it adds an event listener to the element', async function (assert) {
assert.expect(1);

this.set('eventHandler', () => {
assert.ok(true, 'event handler was called');
});

await render(
hbs`<button id="test-button" {{hds-register-event 'click' this.eventHandler}}>Test</button>`
);

await click('button');
});

test('it passes the `useCapture` option to the event listener', async function (assert) {
assert.expect(1);

this.set('eventHandler', (event) => {
assert.strictEqual(
event.eventPhase,
Event.CAPTURING_PHASE,
'event was captured'
);
});

await render(
hbs`<button id="test-button" {{hds-register-event 'click' this.onClick}}>Test</button>`
hbs`<button id="test-button" {{hds-register-event 'click' this.eventHandler useCapture=true}}><span>Test</span></button>`
);
await click('button#test-button');
assert.true(clicked);

await triggerEvent('span', 'click', { bubbles: true });
});
});

0 comments on commit a46238d

Please sign in to comment.