Expands on the example in this tutorial that shows how to use nock to mock the github api. This implementation uses the nockback feature to record the fixtures into separate files. You can then run the tests against the nock mocks rather than the api.
Uses similar technique to the nock-back-mocha module, but one fixture file per test file rather than per test. Thank you to the author for sharing his code on github.
The advantage of implementing it yourself rather than use a separate npm module is that you then have access to the most up to date version of the nock library and all the functionality.
npm install
npm run record
There should be 2 fixture files created in the fixtures folder (internet connection required).
npm test
This will run the tests against the api and then against the mocks so you can see the difference.
- Against the live api (2-3 seconds) - internet connection required
- Against the nock mocks (30-40 milliseconds)
There are npm scripts in package.json to run the tests individually as well.