When using spyOn with jest and typescript I am getting this type error:
Type 'Spy' is not assignable to type 'SpyInstance<{}>'. Property 'mockRestore' is missing in type 'Spy'.
Here is a code example that causes it:
class A {
foo = () => this.bar() + 1;
bar = () => 1;
}
test('should pass', () => {
const a = new A();
let barSpy: jest.SpyInstance;
barSpy = spyOn(a, 'bar');
a.foo();
expect(barSpy).toHaveBeenCalled();
});
When I run this example the test passes, but the typescript complier fails.