对角度教程步骤感到困惑

时间:2014-05-14 21:51:59

标签: javascript angularjs angularjs-scope angular-mock

来自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()之后,它评估为一个空数组,是否可以解释这个谜团?

0 个答案:

没有答案