我正在角度应用程序中的控制器上运行单元测试。到目前为止,我的测试是:
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')
});
});
带控制器
var Controller = function ($scope, $location) {
$scope.submit = function () {
$location.path('/new');
}
}
但是,当我运行它时,我得到了错误browser is not defined
。这里发生了什么?这不是Angular提供的吗?
编辑:更奇怪的是,我收到了inject
未定义的错误。
这是配置文件:
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'
};