Registry /
testing / node-fetch-response-matchers
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ const nodeFetchMatchers = require('node-fetch-response-matchers');
✗ import nodeFetchMatchers from 'node-fetch-response-matchers';
This package uses CommonJS; ESM import may not work directly. Use require() or dynamic import.
chai.use
✓ chai.use(require('node-fetch-response-matchers'));
Typical usage: pass the plugin to chai.use() before using matchers.
successful
✓ expect(fetch('http://example.com')).to.be.successful();
✗ expect(fetch('http://example.com')).to.be.successful;
Matchers must be called as functions (e.g., .successful()) even if no arguments.
Shows how to install, import, and use the plugin with chai to write declarative HTTP response assertions.
const chai = require('chai');
const expect = chai.expect;
const fetch = require('node-fetch');
const nodeFetchMatchers = require('node-fetch-response-matchers');
chai.use(nodeFetchMatchers);
describe('HTTP response tests', function() {
it('should be successful', function() {
return expect(fetch('http://example.com')).to.be.successful();
});
it('should have status 200', function() {
return expect(fetch('http://example.com')).to.haveStatus(200);
});
it('should have body text', function() {
return expect(fetch('http://example.com')).to.haveBodyText('expected text');
});
it('should have header', function() {
return expect(fetch('http://example.com')).to.haveHeader('content-type', 'text/html');
});
});
Errors
Common errors & fixes
TypeError: nodeFetchMatchers is not a function
Using import statement instead of require, or forgetting to call chai.use with the plugin.
fixUse require('node-fetch-response-matchers') and pass it to chai.use() as shown in the example. AssertionError: expected promise to be successful
The HTTP request returned a non-200 status or the promise was rejected (network error).
fixCheck the URL and server status; ensure the server is running and returns 200.
TypeError: expect(...).to.be.successful is not a function
Plugin not registered with chai.use() before using matchers.
fixAdd chai.use(nodeFetchMatchers); before your tests.
Audit
Dependencies
node-fetchrequiredRequired for making HTTP requests that this library matchers test against.
chairequiredRequired as the testing assertion library; this plugin extends chai.