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

docs: testing - highlight dispatchEvent() #22726

Closed
wants to merge 1 commit into from

Conversation

wardbell
Copy link
Contributor

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.

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[x] Documentation content changes
[ ] angular.io application / infrastructure changes
[ ] Other... Please describe:

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?

[ ] Yes
[x] No

@wardbell wardbell added comp: docs target: patch This PR is targeted for the next patch release labels Mar 13, 2018
@wardbell wardbell self-assigned this Mar 13, 2018
@wardbell wardbell changed the title docs: testing - highlight dispatchEvent docs: testing - highlight dispatchEvent() Mar 13, 2018
@mary-poppins
Copy link

You can preview c47990d at https://pr22726-c47990d.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 0b53b71 at https://pr22726-0b53b71.ngbuilds.io/.

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_.
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@wardbell
Copy link
Contributor Author

@petebacondarwin I rephrased the objectionable passage.

@mary-poppins
Copy link

You can preview 971e298 at https://pr22726-971e298.ngbuilds.io/.

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blessings!

@petebacondarwin petebacondarwin added the action: merge The PR is ready for merge by the caretaker label Mar 14, 2018
@ngbot
Copy link

ngbot bot commented Mar 14, 2018

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure status "continuous-integration/travis-ci/pr" is failing
    pending status "code-review/pullapprove" is pending

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

This was referenced Mar 15, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants