Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test and document specifying options to click #553

Merged
merged 1 commit into from Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion addon-test-support/@ember/test-helpers/dom/click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export function __click__(element: Element | Document, options: MouseEventInit):
The exact listing of events that are triggered may change over time as needed
to continue to emulate how actual browsers handle clicking a given element.

Use the `options` hash to change the parameters of the MouseEvents.
Use the `options` hash to change the parameters of the MouseEvents. You can use this to specifiy modifier keys as well. For example:
```javascript
await click('div', { shiftKey: true });
```

@public
@param {string|Element} target the element or selector to click on
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/dom/click-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ module('DOM Helper: click', function(hooks) {
assert.verifySteps(['mousedown 13 17 2', 'mouseup 13 17 2', 'click 13 17 2']);
});

test('clicking accepts modifiers', async function(assert) {
element = buildInstrumentedElement('div', ['clientX', 'clientY', 'button']);
let handler = e => {
assert.equal(e.altKey, true);
};
element.addEventListener('click', handler);
await click(element, { clientX: 13, clientY: 17, altKey: true });
assert.verifySteps(['mousedown 13 17 0', 'mouseup 13 17 0', 'click 13 17 0']);
element.removeEventListener('click', handler);
});

test('clicking a div has window set as view by default', async function(assert) {
element = buildInstrumentedElement('div', ['view']);

Expand Down