Registry / testing / frisby

frisby

JSON →
library2.2.0jsnpmunverified

Frisby.js v2.2.0 is a REST API testing framework built on top of Jest. It provides a fluent API for making HTTP requests and asserting on responses, including status codes, headers, JSON body structure, JSON types via Joi schema validation, and response time. It supports promise-based chaining for dependent HTTP calls, custom expect handlers, and integrates seamlessly with Jest's test runner. Maintained by the community, it sees occasional updates.

npm install frisby
INSTALL
IMPORT
SIG · FRISBY
F
frisby
testingjavascriptv2.2.0
harness data pending
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.

frisby
const frisby = require('frisby');
import frisby from 'frisby';
Frisby is CJS-only; no ESM exports.
Joi
const Joi = require('joi');
import Joi from 'joi';
Joi is also CJS; must be required separately.
frisby.get
frisby.get('/api/endpoint')
frisby({ method: 'GET', url: '/api/endpoint' })
Use dedicated methods (get, post, put, del, patch) instead of generic request.
expect('status', 200)
.expect('status', 200)
.expect(200)
Expect handler takes a string name as first argument.

Demonstrates basic Frisby test with status check, Joi schema validation, and promise chaining.

const frisby = require('frisby'); const Joi = require('joi'); it('should return a user', function () { return frisby.get('https://jsonplaceholder.typicode.com/users/1') .expect('status', 200) .expect('jsonTypes', { id: Joi.number(), name: Joi.string(), username: Joi.string(), email: Joi.string().email() }) .then(function (res) { expect(res.json.id).toBe(1); }); });
Debug
Known issues
breakingFrisby v2.x drops support for Node <14.17.0. If you are on an older Node version, upgrade or stick with v1.x.
fix
Update Node.js to >=14.17.0.
affects: >=2.0.0
deprecatedIn Frisby v2, the `.expect('json')` with a string and value is deprecated in favor of passing an object.
fix
Use `.expect('json', { key: value })` instead of `.expect('json', 'key', value)`.
affects: >=2.0.0 <3.0.0
gotchaFrisby tests must be returned from the Jest `it` callback chain, otherwise the test completes before the HTTP call finishes.
fix
Ensure `return` statement before the Frisby call chain.
affects: >=2.0.0
gotchaJoi schema validation with `.expect('jsonTypes')` may produce cryptic errors if schema does not match; object types must be explicitly defined.
fix
Use Joi.object() for nested objects within jsonTypes.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'joi'
Joi is a peer dependency not automatically installed; missing `joi` package.
fix
Run `npm install --save-dev joi`.
Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout
Test not returning the Frisby spec promise; Jest does not wait for async completion.
fix
Add `return` before the frisby call chain in the `it()` block.
TypeError: frisby.get(...).expect is not a function
Importing frisby incorrectly (e.g., using ES6 import instead of require).
fix
Use `const frisby = require('frisby');` instead of `import frisby from 'frisby';`.
Joi validation error: "value" must be of type object
Using `jsonTypes` with a non-object schema or missing Joi.object() for nested objects.
fix
Ensure schema for jsonTypes uses Joi.object() for nested structures.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
joirequiredFor JSON type validation in expectations
Agent activity
2 hits · last 30 days
node
2
Resources
packagefrisby
frisby — npm install frisby · libregistry