mjgs / nockback-test

Test of nock's nockback feature to record 3rd party api test fixtures into separate files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nockback-test

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.

Install modules:

npm install

Generate the fixture files:

npm run record

There should be 2 fixture files created in the fixtures folder (internet connection required).

Run the tests:

npm test

This will run the tests against the api and then against the mocks so you can see the difference.

  1. Against the live api (2-3 seconds) - internet connection required
  2. Against the nock mocks (30-40 milliseconds)

There are npm scripts in package.json to run the tests individually as well.

About

Test of nock's nockback feature to record 3rd party api test fixtures into separate files


Languages

Language:JavaScript 100.0%