1

Given this code:

function getAnimal(type, color) {
    console.log('blub'); // this is triggered when executing the test
}
this.getAnimal = getAnimal;

and this testing code:

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();
    });
});

But I get this error message: Expected spy function(){return i} to have been called.

So I guess only the this.getAnimal = getAnimal is spied, but not the function. How can I fix this?

GarfieldKlon
  • 11,170
  • 7
  • 31
  • 33

1 Answers1

-1

For such cases you can use rewire. Using rewire you can replace the function/variables inside any module that are not exported

Aditya
  • 771
  • 5
  • 11