1

I'm running unit tests on a controller in an angular app. My test so far is:

describe('Controller', function () {
    var scope, ctrl;
    beforeEach(module('myApp'));
    beforeEach(inject(function ($rootScope,
                                $controller) {
        scope = $rootScope.$new();
        ctrl = $controller('Controller', {
            $scope: scope
        });
    }));
    beforeEach(browser().navigateTo('/'));
    it('should get you to the next page', function () {
        scope.submit();
        expect(browser().location().path()).toBe('/new')
    });
});

with controller

var Controller = function ($scope, $location) {
    $scope.submit = function () {
        $location.path('/new');
    }
}

However, when I run this I get the error browser is not defined. What is going on here? Isn't this provided by Angular?

Edit: Even stranger, I'm getting the error that inject is not defined.

Here's the config file:

basePath = '../';

framework = ["ng-scenario"];

files = [
  ANGULAR_SCENARIO,
  ANGULAR_SCENARIO_ADAPTER,
  'http://code.jquery.com/jquery-1.9.1.min.js',
  'https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js',
  '../static/javascript/angular-mocks.js',
  '../static/javascript/angular-scenario.js',
  '../static/javascript/stripe.js',
  'templates/static/avgrund.jquery.js',
  'templates/static/chosen.jquery.js',
  'templates/static/app.js',
  'tests/E2E/tests.js'
];

urlRoot = '/_karma_/';

singleRun = true;

browsers = ['Chrome'];

junitReporter = {
  outputFile: 'test-output.xml',
  suite: 'e2e'
};
jclancy
  • 49,598
  • 5
  • 30
  • 34

2 Answers2

0

I fixed it. I added the lines

proxies = {
    '/static/': 'http://localhost:5000/static/'
}

and so on for other path you need.

jclancy
  • 49,598
  • 5
  • 30
  • 34
0

Yes. Scenario runner must be run using http or https. Or you can run e2e in a separate html, the format likes this:

<html lang="en">
<head>
<title>End2end Test Runner</title>
<meta charset="utf-8">
<base href="../..">
<script src="app/lib/angular/angular-scenario.js" ng-autotest></script>
<script src="test/e2e/scenarios.js"></script>
</head>
<body>
</body>
</html>

Attention, you must refer this file "angular-scenario.js"

CLoren
  • 298
  • 2
  • 5
  • 10