Categories
TypeScript Answers

How to fix ‘property mock does not exist on type’ error with Jest and TypeScript?

Spread the love

Sometimes, we want to fix ‘property mock does not exist on type’ error with Jest and TypeScript.

In this article, we’ll look at how to fix ‘property mock does not exist on type’ error with Jest and TypeScript.

How to fix ‘property mock does not exist on type’ error with Jest and TypeScript?

To fix ‘property mock does not exist on type’ error with Jest and TypeScript, we can cast the variable with the error to the jest.MockedFunction<typeof addListener> type.

For instance, we write

const addListenerMock = addListener as jest.MockedFunction<typeof addListener>;

to cast the type with as.

Conclusion

To fix ‘property mock does not exist on type’ error with Jest and TypeScript, we can cast the variable with the error to the jest.MockedFunction<typeof addListener> type.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.