Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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())
}
function verify() {
/* jshint expr:true */
if (!nock.isDone()) {
logger.error('pending mocks: %j', nock.pendingMocks());
}
expect(nock.isDone()).to.be.true;
}
afterEach(() => {
assert.ok(nock.isDone(), 'there should be no pending request mocks at the end of a test');
});
.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);
});
});
afterEach(async () => {
assert.ok(nock.isDone(), 'there should be no pending request mocks at the end of a test');
if (oauthdb) {
await oauthdb.close();
}
});
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
})
afterEach(async () => {
assert.ok(nock.isDone(), 'there should be no pending request mocks at the end of a test');
if (oauthdb) {
await oauthdb.close();
}
});
afterEach(() => {
sinon.verifyAndRestore();
if (!nock.isDone()) {
throw new Error('pending mocks: ' + nock.pendingMocks());
}
});
.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);
});
});
afterEach(function() {
vol.reset();
expect(nock.isDone()).toBe(true);
});