鉴于此代码:
function getAnimal(type, color) {
console.log('blub'); // this is triggered when executing the test
}
this.getAnimal = getAnimal;
这个测试代码:
describe('getAnimal()', function() {
it('should get an animal based on type and color', function() {
spyOn(this.AnimalService, 'getAnimal');
this.AnimalService.getAnimal();
expect(this.AnimalService.getAnimal).toHaveBeenCalled();
});
});
但我收到此错误消息: Expected spy function(){return i} to have been called。
所以我猜只有this.getAnimal = getAnimal
被监视的,而不是函数。我怎样才能解决这个问题?