{"id":47240,"library":"chai-fetch-mock","title":"chai-fetch-mock","description":"Chai plugin for fetch-mock library version 3.0.0. Provides Chai assertions for fetch-mock, a mocking library for fetch() and isomorphic-fetch. Active maintenance, weekly release cadence. Differentiator: adds fluent BDD-style assertions like `.called`, `.with.args()`, `.with.url()`, `.with.options()` for fetch-mock routes, requiring careful ordering with other Chai plugins. Supports Node.js 7+ and Chai 3.x/4.x, fetch-mock 5.1.x/6.x. Note: fetch-mock 6.0 requires Node >=7.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/gakimball/chai-fetch-mock","tags":["javascript","chai","fetch","fetch-mock"],"install":[{"cmd":"npm install chai-fetch-mock","lang":"bash","label":"npm"},{"cmd":"yarn add chai-fetch-mock","lang":"bash","label":"yarn"},{"cmd":"pnpm add chai-fetch-mock","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin extends chai assertions","package":"chai","optional":false},{"reason":"Peer dependency; provides the mock fetch object","package":"fetch-mock","optional":false}],"imports":[{"note":"ESM-only export; use import statement or dynamic import()","wrong":"const chaiFetchMock = require('chai-fetch-mock')","symbol":"default (chaiFetchMock)","correct":"import chaiFetchMock from 'chai-fetch-mock'"},{"note":"Pass the plugin function, not a string","wrong":"chai.use('chai-fetch-mock')","symbol":"chai.use","correct":"chai.use(chaiFetchMock)"},{"note":"route() must be called before other assertions, not after","wrong":"expect(fetchMock).to.have.been.called.route('/cats')","symbol":"expect(fetchMock).route(...)","correct":"expect(fetchMock).route('/cats').to.have.been.called"}],"quickstart":{"code":"import chai from 'chai';\nimport chaiFetchMock from 'chai-fetch-mock';\nimport fetchMock from 'fetch-mock';\n\nchai.use(chaiFetchMock);\nconst { expect } = chai;\n\nbefore(() => fetchMock.get('/cats', { cats: 5 }));\n\nexpect(fetchMock).route('/cats').to.have.been.called;\nexpect(fetchMock).route('/cats').to.have.been.called.with.args(['/cats', { cats: 5 }]);\nexpect(fetchMock).route('/cats').to.have.been.called.with.url('/cats');\nexpect(fetchMock).route('/cats').to.have.been.called.with.options({ method: 'GET' });\n\nafter(() => fetchMock.restore());","lang":"javascript","description":"Sets up a fetch mock, applies the chai-fetch-mock plugin, and uses various route assertions."},"warnings":[{"fix":"Always start the assertion chain with .route(urlOrName), e.g., expect(fetchMock).route('/path').to.have.been.called","message":"Route must be defined via route() before using .called, .with.args, .with.url, or .with.options","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Order plugin registration: sin·on-chai first, then chai-fetch-mock","message":"Apply chai-fetch-mock after other plugins like sinon-chai to avoid conflicts with similar vocabulary (e.g., called)","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update to fetch-mock >=6.0.0 and Node >=7","message":"fetch-mock 6.x is required for Node >=7; support for fetch-mock 5.x may be dropped","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Pass array of arguments: [url, options]","message":"`.with.args()` asserts deep equality of the entire arguments array, not just the URL","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Place assertions inside the .then() callback after the fetch promise resolves","message":"Assertions are asynchronous; ensure the fetch call has completed before making assertions (e.g., inside .then() or async/await)","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'3':64 '3.0.0':13 '5.1':69 '6.0':75 '7':61,78 'activ':30 'add':36 'assert':16,41 'bdd':39 'bdd-style':38 'cadenc':34 'call':43 'care':53 'chai':2,5,15,57,63,80 'chai-fetch-mock':1 'differenti':35 'fetch':3,9,19,25,29,49,67,73,81,83 'fetch-mock':8,18,48,66,72,82 'fluent':37 'isomorph':28 'isomorphic-fetch':27 'javascript':79 'librari':11,23 'like':42 'mainten':31 'mock':4,10,20,22,50,68,74,84 'node':77 'node.js':60 'note':71 'order':54 'plugin':6,58 'provid':14 'releas':33 'requir':52,76 'rout':51 'style':40 'support':59 'version':12 'week':32 'with.args':44 'with.options':46 'with.url':45 'x/4.x':65 'x/6.x':70","created_at":"2026-06-07T16:50:30.785809+00:00","updated_at":"2026-06-07T16:50:30.785809+00:00","problems":[{"fix":"const chai = require('chai') or import chai from 'chai'","cause":"chai.use is invoked on a string instead of the chai object","error":"TypeError: chai.use is not a function"},{"fix":"Add .route('/path') before .to.have.been.called","cause":"Forgetting to call .route() before .called","error":"AssertionError: expected [Function] to have been called"},{"fix":"Make sure fetchMock is imported and passed: expect(fetchMock).route(...)","cause":"fetchMock is not passed to expect() or is undefined","error":"TypeError: Cannot read property 'route' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/gakimball/chai-fetch-mock#readme","github":"https://github.com/gakimball/chai-fetch-mock","docs":null,"changelog":null,"pypi":null,"npm":"chai-fetch-mock","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}