Jest use experience, take the return value of the mock interface as an example

Recently the project is trying to access jest

Documentation: https://jestjs.io/

When you want to test files that introduce other files but do not want to test other files, you can mock the other files at this time to achieve the purpose. Of course, when you need to use something in other files (methods or something), you must also mock this thing, otherwise you will not have it when you use it.

For example, I now want to test the a.js file, but I will send an ajax request in the a.js file, and this request method is encapsulated in request.js. At this time, I can mock this request method in a.test.js

a.js

a.test.js

Similar to this, everything you do n’t want to test but need to use can be mocked out in this form, and the error report can also be mocked so that it will not report an error 

Published 123 original articles · Like 73 · Visit 470,000+

Guess you like

Origin blog.csdn.net/DreamFJ/article/details/100888284