There's more....

Should you need to mock some package that you cannot (or won't) inject as a parameter into a function, you can provide Jest with a complete mocked version. Suppose you wanted to mock the "fs" package: you'd start by creating a __mocks__ directory at the same level of the node_modules one, then you would write and place your manual mock code there, and finally you would specify jest.mock("fs") at the beginning of your test file so that Jest will use your module rather than the standard one.

All of this can become a chore, so you'd better try to provide all of the modules as parameters to your functions (as we did with dbConn when deleting regions) so that standard mocks can be used. However, if you can't do that, check out https://facebook.github.io/jest/docs/en/manual-mocks.html for more information.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.192.3