来自https://docs.angularjs.org/tutorial/step_11单元测试部分:
it('should create "phones" model with 2 phones fetched from xhr', function() {
expect(scope.phones).toEqualData([]);
$httpBackend.flush();
expect(scope.phones).toEqualData([{name: 'Nexus S'}, {name: 'Motorola DROID'}]);
});
我只是不明白为什么第2行评估为真,scope.phones
在
[]
scope = $rootScope.$new();
ctrl = $controller(PhoneListCtrl, {$scope: scope});
在ctrl = $controller(PhoneListCtrl, {$scope: scope});
之前
scope.phones
评估为undefined
并且在$httpBackend.flush()
之后,它评估为一个空数组,是否可以解释这个谜团?