I'm working in React Native ts project and using jest + react testing library to test my components.
In a test, I modify a function implementation like this:
test('should be rendered when position is being fetched', async () => { let mockResolve!: (position: { latitude: number; longitude: number; }) => void; jest .spyOn(LoactionService, 'getCurrentPosition') .mockImplementationOnce( (): Promise<{longitude: number; latitude: number}> => { return new Promise(resolve => { mockResolve = resolve; }); }, ); mockResolve({latitude: 0, longitude: 0}); });
But when I call mockResolve({latitude: 0, longitude: 0});
TS return this error: TypeError: mockResolve is not a function
How can I fix it?