Skip to content

test-lib module should export dispatchEvent #4177

Closed

Description

@wardbell

As of alpha-37 it is only available through 'angular2/src/test_lib/utils'

Maybe I'm missing a better technique but the way I know to trigger DOM events is through something like dispatchEvent. For example, I have test code that looks like this:

      // get the HTML element and change its value in the DOM
      var input = rootTC.query(By.css('input')).nativeElement;
      input.value = "Dog Man"
      dispatchEvent(input, 'change'); // event triggers Ng to update model

I think I stole it from one of the Angular core tests.

Alternative (perhaps better?), expose DOM so we can do it ourselves (and more) as in:

  DOM.dispatchEvent(input, DOM.createEvent('change'));

Activity

  1. self-assigned this
    on Oct 2, 2015
  2. juliemr commented on Oct 13, 2015

    @juliemr
    Contributor

    Done with a1fa2e4

  3. IgorMinar commented on Oct 13, 2015

    @IgorMinar
    Contributor

    dispatchEvent was not meant to be public api. it's an internal helper that leaked.

    we should provide a more ergonomic way to trigger events post AngularConnect. in the meantime you can use regular dom apis to create and dispatch events. https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent

  4. angular-automatic-lock-bot commented on Sep 7, 2019

    @angular-automatic-lock-bot

    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.

  5. locked and limited conversation to collaborators on Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions