我目前正在使用Jasmine测试我的AngularJS应用程序,它正在通过规范。我尝试使用Karma运行测试,但是失败了。似乎Karma无法看到在Jasmine规范中定义的$scope,但Jasmine运行器能够正常看到它。
我的karma.conf.js:
frameworks = ['jasmine'];
colors = true;
singleRun = true;
files = [
JASMINE,
JASMINE_ADAPTER,
ANGULAR_SCENARIO,
ANGULAR_SCENARIO_ADAPTER,
'lib/jquery-1.9.1.min.js',
'lib/angular.min.js',
'lib/angular-mocks.js',
'lib/jquery.scrollTo.js',
'lib/jquery-ui.min.js',
'lib/calendar.js',
'lib/date.js',
'src/app.js',
'spec/*.spec.js'
];
browsers = [
'PhantomJS',
'Firefox'
];
我的 test.spec.js 文件:
describe('Application startup', function(){
beforeEach(module('app'));
describe('MainCtrl', function(){
var scope, ctrl;
beforeEach(inject(function($rootScope, $controller){
scope = $rootScope.$new();
ctrl = $controller('MainCtrl', {
$scope: scope
});
}));
it("should initialize $scope.testLoad to 42", function(){
expect(scope.testLoad).toBe(42);
});
});
});
我得到的输出:
expect undefined toBe 42
既然Jasmine没有问题,那显然是Karma或我的配置文件出了问题。发生了什么?