3.0.0 • Published 6 years ago

@teppeis/nock-back-mocha v3.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

@teppeis/nock-back-mocha

Thin wrapper around nock.back that uses different nock files for each test, and cleans up when the mocha test is done.

npm version Node.js Version Support build status dependency status License

Install

$ npm i -D @teppeis/nock-back-mocha

Usage

const nockBackMocha = require('nock-back-mocha')();

describe('Tests!', () => {
  beforeEach(nockBackMocha.beforeEach);
  afterEach(nockBackMocha.afterEach);

  it('makes an http request', () =>
    fetch('http://example.com').then(() => {
      // "/path/to/__nock_fixtures__/Tests!/makes\ an\ http\ request.json"
      console.log(nockBackMocha.fixtureFile);
      nockBackMocha.assertScopesFinished();
    }));
});

API: factory(directory: string?): Context

  • directory: string?: Where do you want the nock files stored? The default is __nock_fixtures__ in the same directory.
  • Context.beforeEach: (this: MochaContext) => Promise<undefined>: Setup nock.back. Call in mocha's beforeEach.
  • Context.afterEach: () => void: Tear down nock.back. Call in mocha's afterEach.
  • Context.fixtureFile: string: Path to the fixture file for the current test.
  • Context.assertScopesFinished: () => void: Assert all nocks in fixture were satisfied. See nock document.

Pro Tip

Use in combination with env NOCK_BACK_MODE to generate http fixtures for your tests

License

MIT License: Teppei Sato <teppeis@gmail.com>

Derived from porchdotcom/nock-back-mocha under ICS license

3.0.0

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago