Executing unit tests on a controller within an Angular application. Current test script:
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 redirect to the next page', function () {
scope.submit();
expect(browser().location().path()).toBe('/new')
});
});
The controller code snippet:
var Controller = function ($scope, $location) {
$scope.submit = function () {
$location.path('/new');
}
}
Encountering an error when running the script - browser is not defined
. Confusion arises as this should be provided by Angular automatically.
Update: Another abnormality, receiving an error stating that inject
is not defined.
Configuration file details:
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'
};