If you been coding with typescript and want to use 'spyOn' on your test you would have to type it like this.
let functionSpy: jest.SpyInstance;
This way we are telling the that it will be a spy instance and we will not have a ts problem.
Now, we are going to see how to actually use it which is really simple.
functionTest.tsx
const FunctionTest = () => {
const bar = () => {
return 'test'
}
return(
<div></div>
)
}
export default FunctionTest
functionTest.test.tsx
functionSpy = jest.spyOn(FunctionTest, 'bar');
Here we can see that following this simple step we are able to spy on the function in order to call it
Hope someone found it useFul.
Lautaro.
Top comments (0)