1

So I'm struggling to setup a mock unit test for my Angular controllers via Protractor. Reason ? It's because I can't figure how to inject Angular mocks into my tests.

Using Karma runner, I have succeeded in setting this up, due to clear examples re: karma.conf.js; however, I need to run full e2e tests with Protractor - and I will need to inject angular controllers.

Here's an example online which demonstrates both Karma unit testing and Protractor e2d testing. https://github.com/mjhea0/angular-testing-tutorial/tree/master/tests

In karma.conf.js, you can use the files: [ ... ] property to specify angular-mocks.js, etc. However, in protractor.conf.js there seems to be no such thing.

Take this example that from git repo above :

beforeEach(function () {
    module('myApp');
  });

  beforeEach(inject(function ($controller, $rootScope) {
    $scope = $rootScope.$new();
    controller = $controller('TestOneController', {
      $scope: $scope
    });
}));

This works when running the unit test with Karma, but how to run this with Protractor ?

It uses module() and inject(), but that using angular-mocks.js. Would I use require() to make this happen ?

Or is it somewhere along the lines that this post discusses ? http://blog.ng-book.com/how-to-mock-http-requests-in-protractor/

Advice and guidance is appreciated...

Bob

bob.mazzo
  • 5,183
  • 23
  • 80
  • 149

0 Answers0