This repo contains runnable minimal reproducable examples of where I've been stuck in the past trying to work out how to mock something, and (maybe) the solution.
The aim of this repo is to:
Feel free to PR with any other jest testing puzzles you've faced!
process.platform
)fs.readdir
)childProcess.execFile
) wihout __mocks__$ yarn # install node_modules
$ yarn test # runs Jest
There are many ways to unit test, and I'm not suggesting what's "good" or "bad". This section just provides context as to why the solutions here may or may not look idiosyncratic.
For the most part, test files usually:
I personally don't usually define manual mock files for modules, and prefer to inline the mocking where possible. This is because:
__setMockFiles
(as seen in the the Jest docs example) to provide this "dynamic mock" behaviour.