我正在開發角度的web應用程序。 下面是我的控制器的方法,當錯誤happends將設置fetchPlayersFailed爲true:
$scope.fetchAllPlayers = function() {
$scope.players = PlayerFact.query({
active: true
},
undefined,
function() {
console.log('set fetchPlayersFailed to true');
$scope.fetchPlayersFailed = true;
}
);
};
但是當我運行單元測試,誤差在這種方法中發生,下面是我寫的規格:
it('fetchAllPlayers: should set fetchPlayersFailed to true when error happens', function() {
httpBackend.expectGET('/api/players?active=true').respond(500);
scope.fetchAllPlayers();
httpBackend.flush();
expect(scope.fetchPlayersFailed).toEqual(true);
});
這裏的錯誤:
Chrome 32.0 (Windows) Controller: PlayerCtrl fetchAllPlayers: should set fetchPl
ayersFailed to true when error happens FAILED
Expected false to equal true.
Error: Expected false to equal true.
at null.<anonymous> (C:/Users/I056958/Documents/My Own/javascript wo
rkspace/redjoker/test/spec/controllers/player.js:111:38)
爲什麼fetchPlayersFailed沒有被設置爲true?
是消息'設置fetchPlayersFailed到TRUE'登錄到控制檯? – dfsq
是的,它已記錄。 –