0
我正在使用AngularJS实现我的第一个Web应用程序(只是遵循AngularJS教程),我正在使用Jasmine和Karma编写一些测试。茉莉花规格失败
这是我app.spec.js
文件:
describe('PhoneListController', function() {
beforeEach(module('phonecatApp'));
it('should create a `phones` model with 3 phones', inject(function($controller) {
var scope = {};
var ctrl = $controller('PhoneListController', {$scope: scope});
expect(scope.phones.length).toBe(3);
expect(scope.name).toBe('world');
}));
});
哪个正常工作。但是,当我将其更改为:
describe('PhoneListController', function() {
beforeEach(module('phonecatApp'));
it('should create a `phones` model with 3 phones', inject(function($controller) {
var scope = {};
var ctrl = $controller('PhoneListController', {$scope: scope});
expect(scope.phones.length).toBe(3);
}));
it('should have world as a name', inject(function($controller) {
expect(scope.name).toBe('world');
}));
});
第二种方法有什么问题?我认为,大致上,每个it
声明对应于一个测试用例,并且每个describe
声明对应于一个测试用例。那是错的吗?
谢谢。
简单; 'scope'在你的第二个'it'函数中没有定义。它只在第一次被定义 – Phil