Gathering detailed insights and metrics for chai-nock
Gathering detailed insights and metrics for chai-nock
Gathering detailed insights and metrics for chai-nock
Gathering detailed insights and metrics for chai-nock
npm install chai-nock
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
4 Stars
18 Commits
1 Forks
2 Watching
1 Branches
5 Contributors
Updated on 07 Oct 2023
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-1.9%
568
Compared to previous day
Last week
-3.5%
4,139
Compared to previous week
Last month
15.7%
16,289
Compared to previous month
Last year
-36.8%
150,855
Compared to previous year
Nock Chai extends Chai with a language for asserting facts about Nock.
Instead of manually wiring up your expectations to intercepting a nocked request:
1const nockedRequest = nock('http://some-url'); 2 3nockedRequest.on('request', function(req, interceptor, body) { 4 expect(body).to.deep.equal({ hello: 'world' }); 5});
you can write code that expresses what you really mean:
1return expect(nock('http://some-url')).to.have.been.requestedWith({ 2 hello: 'world' 3});
npm install chai-nock
Then add to your test setup:
1const chai = require('chai'); 2const chaiNock = require('chai-nock'); 3 4chai.use(chaiNock);
Asserts that a request has been made to the nock.
1it('requested', () => { 2 const requestNock = nock('http://bbc.co.uk') 3 .get('/') 4 .reply(200); 5 6 request({ 7 uri: 'http://bbc.co.uk', 8 }); 9 10 return expect(requestNock).to.have.been.requested; 11});
Asserts that a request has been made to the nock with a body that exactly matches the object provided.
1it('requestedWith', () => { 2 const requestNock = nock('http://bbc.co.uk') 3 .get('/') 4 .reply(200); 5 6 request({ 7 json: true, 8 uri: 'http://bbc.co.uk', 9 body: { 10 hello: 'world' 11 } 12 }); 13 14 return expect(requestNock).to.have.been.requestedWith({ hello: 'world' }); 15});
Asserts that a request has been made to the nock with headers that exactly match the object provided.
1it('requestedWithHeaders', () => { 2 const requestNock = nock('http://bbc.co.uk') 3 .get('/') 4 .reply(200); 5 6 request({ 7 json: true, 8 uri: 'http://bbc.co.uk', 9 headers: { 10 myHeader: 'myHeaderValue' 11 } 12 }); 13 14 return expect(requestNock).to.have.been.requestedWithHeaders({ 15 host: 'bbc.co.uk', 16 accept: 'application/json', 17 myHeader: 'myHeaderValue' 18 }); 19});
Asserts that a request has been made to the nock with headers that contain the key/value pairs in the object provided.
1it('requestedWithHeadersMatch', () => { 2 const requestNock = nock('http://bbc.co.uk') 3 .get('/') 4 .reply(200); 5 6 request({ 7 json: true, 8 uri: 'http://bbc.co.uk', 9 headers: { 10 myHeader: 'myHeaderValue', 11 otherHeader: 'otherHeaderValue' 12 } 13 }); 14 15 return expect(requestNock).to.have.been.requestedWithHeadersMatch({ 16 myHeader: 'myHeaderValue' 17 }); 18});
setTimeout
on the chaiNock
object:1const chaiNock = require('chai-nock'); 2 3chai.use(chaiNock); 4// Set a timeout of 10 seconds 5chaiNock.setTimeout(10000);
1jest.setTimeout(12000);
1const { expect } = require('chai'); 2const nock = require('nock'); 3const request = require('request-promise-native'); 4 5describe('example', () => { 6 it('test', () => { 7 const requestNock = nock('http://bbc.co.uk') 8 .get('/') 9 .reply(200); 10 11 request({ 12 json: true, 13 uri: 'http://bbc.co.uk', 14 body: { 15 hello: 'world' 16 } 17 }); 18 19 return expect(requestNock).to.have.been.requestedWith({ hello: 'world' }); 20 }); 21});
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/18 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
49 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More