来自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});
beforectrl = $controller(PhoneListCtrl, {$scope: scope});
scope.phones
评估为undefined
和 after but before $httpBackend.flush()
,它评估为一个空数组,有人可以解释一下这个谜吗?