-
Notifications
You must be signed in to change notification settings - Fork 12
Add `@validateOn="input", rename "blur" to "focusout" #31
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { find, triggerEvent } from '@ember/test-helpers'; | ||
|
||
/** | ||
* Fill the provided text into the `value` property of the selected form element, similar to `fillIn`, but *without* implicitly triggering a `change` event. | ||
* This mimics the behavior of a user typing data into an input without yet focusing out of it. Browsers will only trigger a `change` event when focusing | ||
* out of the element, not while typing! | ||
* | ||
* `fillIn` will basically simulate entering the data *and* kinda focusing out (as it triggers `change`, however not `focusout`, which is impossible to achieve as a real user), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😮 I did NOT know this! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, had to confirm this for myself by looking up their source. I should probably create an issue. I guess we cannot change the existing behaviour of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed this: emberjs/ember-test-helpers#1336 |
||
* while this helper does only the former. | ||
*/ | ||
export async function input(selector: string, value: string): Promise<void> { | ||
const el = find(selector); | ||
|
||
if (!el) { | ||
throw new Error(`No element found for selector ${selector}`); | ||
} | ||
|
||
if (!(el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)) { | ||
throw new Error(`Invalid element for \`input\` helper.`); | ||
} | ||
|
||
el.value = value; | ||
await triggerEvent(el, 'input'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10/10 would read again