A mock function that caches function responses so you won't need to write mocks by hand.
cachemock will record the result of asynchronous calls the first time they're
done, so the second time you call a funcion with the same parameters, instead of
calling it again, the cache will be used.
const cachemock = ;const get = ;// this will be called;
npm install --save-dev cachemock
Imagine that you implement some function that uses the library
call some REST API.
If you want to test your function, you would normally need to write a mock response by hand. If you have lots of functions that do HTTP requests, this becomes tiresome quickly.
You can use
cachemock to cache the responses:
const cachemockfile = ;const getCached = ;;
The first time you run your tests all calls will effectively be made. A file will be created in your root directory with the name
.get.json. The second time your run your tests this file wiil be read and the calls are going to be mocked.
Note that we have used dependency injection in our example function. If your function does not use dependency injection, you could use a library that patches dependencies such as
If you use
cachmockfile, you can specify the folder you want to save your cache. The folder has to exist.
const cachemockfile = ;const getCached = ;