Using Karma to scenario test an AngularJS controller?

188 views Asked by At

Here is what I have tried:

$ git clone https://github.com/angular/angular-seed my_project && cd my_project
$ rm -rf app update_angular.js test/e2e/scenarios.js
$ touch test/e2e/scenarios.js

I then pasted code from AngularJS's official ngMock.$httpBackend docs into:

test/e2e/scenarios.js

'use strict';                               // Line 1

function MyController($scope, $http) {...}  // Lines 3-22

describe('MyController', function() {...}   // Lines 24-87

Error

Unfortunately when I run the tests using config/karma-e2e.conf, I get:

ReferenceError: inject is not defined at
                http://localhost:9876/base/test/e2e/scenarios.js?1387679134000:31
1

There are 1 answers

0
Eitan Peer On BEST ANSWER

inject is defined in angular-mocks file, and is intended for unit tests only. If you're using Karma just add it to the files array.

e2e tests are on top of the browser, and run by angular-scenario. you can't inject any Angular components there.

BTW the Angular team are in the process of migrating their functional testing to protractor which is based on Selenium. I'd catch up with that instead of the angular-scenario testing framework. Protractor is a lot better.