Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
node-fetch-response-matchers
Advanced tools
Chai asserts for node-fetch response promise, make your tests with http more declarative
Chai plugin with matchers for node-fetch promise response. It helps the tests to be more declarative.
it('some-test', function(){
return expect(fetch('http://localhost/')).to.be.successful()
.and.to.haveBodyText('foo');
});
it('some-test', function(done){
fetch('http://localhost/')
.then(res => {
expect(res.status).to.equal(200);
return res.text();
}).then(text => {
expect(text).to.equal('foo');
done();
})
});
$ npm install --save-dev node-fetch-response-matchers
const nodeFetchMatchers = require('node-fetch-response-matchers');
const fetch = require('node-fetch');
const chai = require('chai');
chai.use(nodeFetchMatchers);
describe('test suite', function(){
it('http success test', function(){
return expect(fetch('http://localhost/')).to.be.successful();
});
it('and', function(){
return expect(fetch('http://localhost/')).to.be.successful()
.and.haveBodyText('foo');
});
});
You can all use chai "not"
it('not', function(){
return expect(fetch('http://localhost/')).to.not.be.successful();
});
it('http success test', function(){
return expect(fetch('http://localhost/')).to.be.successful();
});
it('http status assert', function(){
return expect(fetch('http://localhost/')).to.haveStatus(500);
});
API function | params | description |
---|---|---|
successful() | () | Assert that the status is 200 OK |
created() | () | Assert that the status is 201 |
badRequest() | () | Assert that the status is 400 |
unauthorized() | () | Assert that the status is 401 |
rejected() | () | Assert that the status is 403 |
notFound() | () | Assert that the status is 404 |
serverError() | () | Assert that the status is 500 |
serviceUnAvailable() | () | Assert that the status is 503 |
haveStatus() | (status) | Assert that the status is provided number argument |
it('have body object', () => {
return expect(fetch('http://localhost/').to.haveBodyObject({foo: 'bar'});
});
API function | params | description |
---|---|---|
haveBodyObject() | (obj) | Assert equal provided object |
haveBodyText() | (text) | Assert equal provided string text |
haveBodyBuffer() | (Buffer) | Assert equal provided Node Buffer |
haveBodyRegexpMatch() | (regexp) | Assert match body on regular expression |
haveBodyThat() | (predicate(text)) | Assert match body on provided function predicate on the text |
it('have header', () => {
return expect(fetch('http://localhost/').to.haveHeader('connection', 'close');
});
API function | params | description |
---|---|---|
haveHeader() | (name, value) | Assert that response contains header by provided name and value |
headerExists() | (name) | Assert that response contains header by provided name |
haveHeaderThat() | (name, predicate(value)) | Assert that header with given name have true on the value for a given predicate |
haveHeaders() | (headersMap) | Assert that given key-value headers are exists in headers response |
it('have cookie', () => {
return expect(fetch('http://localhost/').to.haveCookie('foo', 'bar');
});
API function | params | description |
---|---|---|
haveCookieByName() | (name) | Assert that cookie by name is written to the response |
haveCookie() | (name, value) | Assert that cookie by name and value is written to the response |
haveCookieThat() | (name, predicate(cookie)) | Assert that cookie by name and match given predicate on cookie properties |
it('must-revalidate', () => {
return expect(fetch('http://localhost/').to.have.cacheControlMustRevalidate();
});
it('max-age', () => {
return expect(fetch('http://localhost/').to.have.cacheControlmMaxAge(120);
});
API function | params |
---|---|
cacheControlMustRevalidate() | () |
cacheControlNoCache() | () |
cacheControlNoStore() | () |
cacheControlNoTransform() | () |
cacheControlPublic() | () |
cacheControlPrivate() | () |
cacheControlProxyMaxRevalidate | () |
cacheControlmMaxAge() | (age-in-sec) |
cacheControlSMaxAge() | (age-in-sec) |
FAQs
Chai asserts for node-fetch response promise, make your tests with http more declarative
The npm package node-fetch-response-matchers receives a total of 102 weekly downloads. As such, node-fetch-response-matchers popularity was classified as not popular.
We found that node-fetch-response-matchers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.