所以我正在浏览AngularJS教程,我在第5章,我遇到了这个Karma测试。它看起来像这样:
IsAttachment==true
它正在测试的代码如下所示:
'use strict';
/* jasmine specs for controllers go here */
describe('PhoneCat controllers', function() {
describe('PhoneListCtrl', function(){
var scope, ctrl, $httpBackend;
beforeEach(module('phonecatApp'));
beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
$httpBackend = _$httpBackend_;
$httpBackend.expectGET('phones/phones.json').
respond([{name: 'Nexus S'}, {name: 'Motorola DROID'}]);
scope = $rootScope.$new();
ctrl = $controller('PhoneListCtrl3', {$scope: scope});
}));
it('should create "phones" model with 2 phones fetched from xhr', function() {
expect(scope.phonez).toBeUndefined();
$httpBackend.flush();
expect(scope.phonez).toEqual([{name: 'Nexus S'},
{name: 'Motorola DROID'}]);
});
it('should set the default value of orderProp model', function() {
expect(scope.orderProp).toBe('age');
});
});
});
我的问题是,为什么他们两次打电话描述?我从测试中删除了初始描述,即'use strict';
/* Controllers */
var phonecatApp1 = angular.module('phonecatApp', []);
phonecatApp1.controller('PhoneListCtrl3', ['$scope', '$http', function($scope, $http) {
$http.get('phones/phones.json').success(function(data) {
$scope.phonez = data;
}).error(function(data, status) {
$scope.err = "Cannot make connection to data. Reason: " + status + data;
console.log("Error status : " + status);
});
$scope.orderProp = 'age';
}]);
,测试通过没有任何问题。
感谢您的时间。
答案 0 :(得分:2)
描述方法添加了一个测试套件,它只是用于分离测试用例 -
见下面的例子 -
describe('PhoneCat controllers', function() {
describe('PhoneListCtrl', function(){
//Phone list controller tests goes here
}
describe('PhoneDetailsCtrl', function(){
//Phone details controller tests goes here
}
}

除了测试用例中的分离外,它只添加了它。 Click here了解有关描述方法的更多信息