Angular 5 – End to End testing with ngModel

Issue

in last week we are trying to add e2e testing to our project, but it seems (after a big research in the web) there is no library that can work with Angular ngModel (version 2+).

what can we do ? is there anything except from protractor, which is not support Angular 2 ngModel and binding ?

html example:

I need to look for the following model “data.user.name”.

thanks.

Solution

There is no problem using proactor for ngModel.
Please consider looking in this repository

I already use it. You only need to take the e2e directory and looking in the package.json what are the dev dependency.


Edit for your edit: Accessing internal modal “data.user.name”

You should not use e2e tests for that, that is a non sense. You need regular unit testing for each of your component. Please consider reproducing what there is in the *.spec.ts in the src directory. See also the test-config in the above mentionned repository.

The official doc for unit testing is here

To conclude:

  • Accessing the component and its values, like data.user.name is on test-unit side, Angular provide a heavy doc (but well made) for that.
  • Accessing the DOM is on the e2e side, with regular javascript API, like these:
    expect(userNameField.getAttribute('value')).toContain('myusername');

Answered By – David Faure

Answer Checked By – Timothy Miller (AngularFixing Admin)

Leave a Reply

Your email address will not be published.