3

I'm switching all of our protractor E2E tests of an angular app to ngMock, so that we can mock our resources/http calls. However, I can't find a recommended method for loading ngMock in that scenario.

I don't want to include the script itself in my live app of course, but I'm not seeing a clear method through protractor for injecting an extra script element, or dynamically loading it.

helion3
  • 34,737
  • 15
  • 57
  • 100

1 Answers1

0

You can do is to use grunt-targethtml or gupl-targethtml so in your index.html you can add conditions of when to add an script or not:

    <!--(if target  mock || e2e)><!-->
    <script src="dev-mocks/mock-utils.js"></script>
    <script src="dev-mocks/modules/authentication-service-mock.js"></script>
    <!--<!(endif)-->

First configure your grunt task to execute the targethtml task with the target e2e/mock

 grunt.registerTask(
    'e2e',
    'Automated tests',
    function(target) {
      var tasks = [
          'clean:server',
          'targethtml:e2e',
          'concurrent:server',
          'autoprefixer',
          'connect:e2e'
        ];
        return grunt.task.run(tasks);
    });

Here is a working template with all the tasks, packages and logic necessary to implement Protractor + CucumberJS + sugar-step (for easy sync-async steps executions), and also inject mock modules dinamically using the @Around method of CucumberJS

  • 1
    I really don't want ngMock anywhere in my actual application templates, even if it's just going to be removed in a gulp task, but part of the issue is that everything in the app is loaded with `requirejs`. – helion3 May 22 '15 at 00:19
  • The cleaner way is yo use targethtml, Otherwise you will have to do what targethtml does by hand, has you said, using requiredjs with a particular gulp task and load the mock modules into your angular application manually – Matias Fernandez Martinez May 22 '15 at 00:22