How to use the nock.isDone function in nock

To help you get started, we’ve selected a few nock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nock / nock / types / tests.ts View on Github external
// Expectations
let google = nock('http://example.test')
  .get('/')
  .reply(200, 'Hello from Google!')
setTimeout(() => {
  google.done() // will throw an assertion error if meanwhile a "GET http://example.test" was not performed.
}, 5000)

/// .isDone()
scope = nock('http://example.test')
  .get('/')
  .reply(200)
scope.isDone() // will return false

nock.isDone()

/// .cleanAll()
nock.cleanAll()

/// .persist()
scope = nock('http://example.test')
  .persist()
  .get('/')
  .reply(200, 'Persisting all the way')

/// .pendingMocks()
strings = scope.pendingMocks()
strings = nock.pendingMocks()
if (!scope.isDone()) {
  console.error('pending mocks: %j', scope.pendingMocks())
}
github cloudfoundry-incubator / service-fabrik-broker / test / test_deployment_hooks / mocks / index.js View on Github external
function verify() {
  /* jshint expr:true */
  if (!nock.isDone()) {
    logger.error('pending mocks: %j', nock.pendingMocks());
  }
  expect(nock.isDone()).to.be.true;
}
github mozilla / fxa-auth-server / test / local / backendService.js View on Github external
afterEach(() => {
    assert.ok(nock.isDone(), 'there should be no pending request mocks at the end of a test');
  });
github npms-io / npms-cli / test / open.spec.js View on Github external
.catch((err) => {
            expect(err.status).to.equal(1);
            expect(err.output.stderr).to.contain('ERROR\n');
            expect(err.output.stderr).to.contain('SOME_ERROR');
            expect(err.output.stderr).to.contain('Some error');
            expect(nock.isDone()).to.equal(true);
        });
    });
github mozilla / fxa-auth-server / test / local / oauthdb / check-refresh-token.js View on Github external
afterEach(async () => {
    assert.ok(nock.isDone(), 'there should be no pending request mocks at the end of a test');
    if (oauthdb) {
      await oauthdb.close();
    }
  });
github unlock-protocol / unlock / unlock-js / src / __tests__ / helpers / nockHelper.js View on Github external
getUnusedNocks() {
    if (nock.isDone()) return []
    const unused = Object.values(this.nockScope.keyedInterceptors).map(
      interceptors =>
        interceptors
          .map(interceptor => {
            return (
              interceptor.interceptionCounter === 0 && {
                api: interceptor._requestBody,
                reply: interceptor.body,
              }
            )
          })
          .filter(a => a)
    )
    unused.sort((a, b) => {
      return a.api.id < b.api.id ? -1 : 1
    })
github mozilla / fxa-auth-server / test / local / oauthdb / grant-tokens-from-session-token.js View on Github external
afterEach(async () => {
    assert.ok(nock.isDone(), 'there should be no pending request mocks at the end of a test');
    if (oauthdb) {
      await oauthdb.close();
    }
  });
github voxpelli / webpage-webmentions / test / functional / api.spec.js View on Github external
afterEach(() => {
    sinon.verifyAndRestore();

    if (!nock.isDone()) {
      throw new Error('pending mocks: ' + nock.pendingMocks());
    }
  });
github npms-io / npms-cli / test / search.spec.js View on Github external
.then((output) => {
            expect(output.stdout).to.contain('┌──');
            expect(output.stdout).to.contain('│ Package');
            expect(output.stdout).to.contain('│ gulp •');
            expect(nock.isDone()).to.equal(true);
        });
    });
github Crypto-Punkers / resolver-engine / test / __tests__ / resolvers / urlresolver.spec.ts View on Github external
afterEach(function() {
    vol.reset();
    expect(nock.isDone()).toBe(true);
  });