Frisby.js an API testing tool built on top of Jest that makes testing API endpoints easy, fast and fun.
Install Frisby v2.x from NPM into your project:
npm install frisby --save-dev
The minimum setup to run a single test expectation.
const frisby = ;;
Nested Dependent HTTP Calls
A more complex example with nested dependent Frisby tests with Frisby's Promise-style
const frisby = ;const Joi = frisbyJoi; // Frisby exposes Joi for convenience;
Built-In Expect Handlers
Frisby comes with many handy built-in expect handlers to help you test the HTTP response of your API.
status- Check HTTP status
header- Check HTTP header key + value
json- Match JSON structure + values (RegExp can be used)
jsonStrict- Match EXACT JSON structure + values (extra keys not tested for cause test failures)
jsonTypes- Match JSON structure + value types
jsonTypesStrict- Match EXACT JSON structure + value types (extra keys not tested for cause test failures)
bodyContains- Match partial body content (string or regex)
responseTime- Check if request completes within a specified duration (ms)
Define Custom Expect Handlers
When Frisby's built-in expect handlers are not enough, or if you find yourself running the same expectations in multiple places in your tests, you can define your own custom expect handler once, and then run it from anywhere in your tests.
;// Use our new custom expect handler;;
Expecting JSON types using Joi
Using Jasmine Matchers Directly
Any of the Jasmine matchers
can be used inside the
then method to perform additional or custom tests on
the response data.
const frisby = ;;
Frisby uses Jasmine style assertion syntax, and uses Jest to run tests.
Jest can run sandboxed tests in parallel, which fits the concept of HTTP testing very nicely so your tests run much faster.
npm install --save-dev jest
Create your tests
mkdir __tests__ touch __tests__/api.spec.js
Run your tests from the CLI
cd your/project jest
Licensed under the BSD 3-Clause license.