Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React native jest TypeError: mockResolve is not a function

$
0
0

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?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>