-
Notifications
You must be signed in to change notification settings - Fork 26.2k
docs: testing - highlight dispatchEvent() #22726
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
Conversation
You can preview c47990d at https://pr22726-c47990d.ngbuilds.io/. |
c47990d
to
0b53b71
Compare
You can preview 0b53b71 at https://pr22726-0b53b71.ngbuilds.io/. |
aio/content/guide/testing.md
Outdated
To simulate user input, you can find the input element and set its `value` property. | ||
Then call `fixture.detectChanges()` to trigger Angular's change detection. | ||
|
||
This _almost works_. |
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.
I'm not quite sure that this is the correct conversational style for the guide?
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.
It sort of implies that something is wrong with Angular.
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.
I agree that maybe the sentence is not needed. More like because it says "All I said is not what you want, so forget about it and then let me explain it good now"
But with all due respect, I do think that something is wrong with Angular. All of this shouldn't be needed and detectChanges
by itself should be enough.
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.
I didn't intend to suggest there was something wrong with Angular but rather that we might not expect this. I will rephrase.
0b53b71
to
971e298
Compare
@petebacondarwin I rephrased the objectionable passage. |
You can preview 971e298 at https://pr22726-971e298.ngbuilds.io/. |
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.
Blessings!
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I spent hours trying to make Angular recognize the value entered into an input box of a form.
The solution -
inputElement.dispatchEvent(newEvent('input'));
- was hiding in Testing sample code but the guide did not speak to it. Obviously I knew the answer once long ago but had forgotten it.I got no help searching the web.
I only remembered the answer when I looked at integration tests for the Angular Reactive Forms. Our readers should not have to work so hard to learn this technique.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
It devotes a new section to usage of
dispatchEvent
.What is the current behavior?
This critical technique was not covered (although examples of it were visible in several examples)
What is the new behavior?
Usage called out just after
detectChanges()). Go to
~/guide/testing#dispatch-event`.Does this PR introduce a breaking change?