2

I have some protractor tests and I would like to mock some calls to a third party service used by my Angular JS app.

I've read about ngMockE2E. My understanding is this requires I add angular-mocks.js to my page.

What are the best practices including angular-mocks.js in a page? Should I use some sort of pre-processor to remove it or is it somehow safe for use in a production environment?

objectuser
  • 671
  • 6
  • 15

1 Answers1

2

Protractor allows you to add arbitrary mock modules via browser.addMockModule() (which would though still require angular-mocks module to be loaded). Sample usages:

Should I use some sort of pre-processor to remove it or is it somehow safe for use in a production environment?

I would solve it on the application build level (with grunt or gulp, for example). Install angular-mocks package and include in the build only for the dev/test environment.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thanks @alecxe. The second reference says "it is essential that the script angular-mocks.js is referenced in your AngularJS application". Are you saying that's not the case? – objectuser Feb 11 '16 at 22:35
  • @objectuser from what I know of, angular-mocks are not needed for that to work. Please check. – alecxe Feb 11 '16 at 23:43
  • 1
    I followed the second link and it works with angular-mocks.js included in the HTML file but not without it. – objectuser Feb 12 '16 at 02:24