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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *