All Projects → vlucas → Frisby

vlucas / Frisby

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Frisby

Dredd
Language-agnostic HTTP API Testing Tool
Stars: ✭ 3,770 (+154.04%)
Mutual labels:  integration-testing, testing-framework
Node Express Boilerplate
A boilerplate for building production-ready RESTful APIs using Node.js, Express, and Mongoose
Stars: ✭ 890 (-40.03%)
Mutual labels:  rest-api, jest
Jasmine Matchers
Write Beautiful Specs with Custom Matchers for Jest and Jasmine
Stars: ✭ 552 (-62.8%)
Mutual labels:  jest, jasmine
Gest
👨‍💻 A sensible GraphQL testing tool - test your GraphQL schema locally and in the cloud
Stars: ✭ 109 (-92.65%)
Mutual labels:  jest, integration-testing
Karmatic
🦑 Easy automatic (headless) browser testing with Jest's API, but powered by Karma & Webpack.
Stars: ✭ 1,178 (-20.62%)
Mutual labels:  jest, jasmine
Jest Puppeteer
Run your tests using Jest & Puppeteer 🎪✨
Stars: ✭ 3,267 (+120.15%)
Mutual labels:  jest, integration-testing
Public
Repository for wallaby.js questions and issues
Stars: ✭ 662 (-55.39%)
Mutual labels:  jest, jasmine
angular-unit-testing-examples
Showroom for different Angular unit testing concepts
Stars: ✭ 19 (-98.72%)
Mutual labels:  jasmine, jest
Moveit
🚀 NLW #4 | React+ TypeScript + NextJS + StyledComponents + Firebase + MongoDb +Axios
Stars: ✭ 39 (-97.37%)
Mutual labels:  rest-api, jest
Jest To Match Shape Of
A Jest matcher to verify the shape of an object. Makes integration testing simple.
Stars: ✭ 34 (-97.71%)
Mutual labels:  jest, integration-testing
Rxjs Marbles
An RxJS marble testing library for any test framework
Stars: ✭ 267 (-82.01%)
Mutual labels:  jest, jasmine
Automation Arsenal
Curated list of popular Java and Kotlin frameworks, libraries and tools related to software testing, quality assurance and adjacent processes automation.
Stars: ✭ 105 (-92.92%)
Mutual labels:  integration-testing, testing-framework
awesome-javascript-testing
🔧 Awesome JavaScript testing resources
Stars: ✭ 28 (-98.11%)
Mutual labels:  jest, integration-testing
Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (-78.3%)
Mutual labels:  jest, jasmine
eslint-config-adjunct
A reasonable collection of plugins to use alongside your main esLint configuration
Stars: ✭ 39 (-97.37%)
Mutual labels:  jasmine, jest
Clean Ts Api
API em NodeJs usando Typescript, TDD, Clean Architecture, Design Patterns e SOLID principles
Stars: ✭ 619 (-58.29%)
Mutual labels:  rest-api, jest
api-test
🌿 A simple bash script to test JSON API from terminal in a structured and organized way.
Stars: ✭ 53 (-96.43%)
Mutual labels:  integration-testing, testing-framework
kheera-testrunner-android
BDD Framework for Android
Stars: ✭ 18 (-98.79%)
Mutual labels:  integration-testing, testing-framework
Enzyme Matchers
Jasmine/Jest assertions for enzyme
Stars: ✭ 881 (-40.63%)
Mutual labels:  jest, jasmine
Dockest
Docker + Jest integration testing for Node.js
Stars: ✭ 81 (-94.54%)
Mutual labels:  jest, integration-testing

Frisby

NPM CI

Frisby.js

Introduction

Frisby.js an API testing tool built on top of Jest that makes testing API endpoints easy, fast and fun.

Installation

Install Frisby v2.x from NPM into your project:

npm install --save-dev frisby joi

Creating Tests

Simple Example

The minimum setup to run a single test expectation.

const frisby = require('frisby');

it('should be a teapot', function () {
  // Return the Frisby.js Spec in the 'it()' (just like a promise)
  return frisby.get('http://httpbin.org/status/418')
    .expect('status', 418);
});

Nested Dependent HTTP Calls

A more complex example with nested dependent Frisby tests with Frisby's Promise-style then method.

const frisby = require('frisby');
const Joi = require('joi');

describe('Posts', function () {
  it('should return all posts and first post should have comments', function () {
    return frisby.get('http://jsonplaceholder.typicode.com/posts')
      .expect('status', 200)
      .expect('jsonTypes', '*', {
        userId: Joi.number(),
        id: Joi.number(),
        title: Joi.string(),
        body: Joi.string()
      })
      .then(function (res) { // res = FrisbyResponse object
        let postId = res.json[0].id;

        // Get first post's comments
        // RETURN the FrisbySpec object so function waits on it to finish - just like a Promise chain
        return frisby.get('http://jsonplaceholder.typicode.com/posts/' + postId + '/comments')
          .expect('status', 200)
          .expect('json', '*', {
            postId: postId
          })
          .expect('jsonTypes', '*', {
            postId: Joi.number(),
            id: Joi.number(),
            name: Joi.string(),
            email: Joi.string().email(),
            body: Joi.string()
          });
      });
  });
});

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.

beforeAll(function () {
  // Add our custom expect handler
  frisby.addExpectHandler('isUser1', function (response) {
    let json = response.body;

    // Run custom Jasmine matchers here
    expect(json.id).toBe(1);
    expect(json.email).toBe('[email protected]');
  });
});

// Use our new custom expect handler
it('should allow custom expect handlers to be registered and used', function () {
  return frisby.get('https://api.example.com/users/1')
    .expect('isUser1')
});

afterAll(function () {
  // Remove said custom handler (if needed)
  frisby.removeExpectHandler('isUser1');
});

Expecting JSON types using Joi

With Frisby, you can use Joi to set the expectation that the JSON body response from the HTTP call meets a defined schema. Check out the Joi API for more details.

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 = require('frisby');

it('should be user 1', function () {
  return frisby.get('https://api.example.com/users/1')
    .then(function (res) {
      expect(res.json.id).toBe(1);
      expect(res.json.email).toBe('[email protected]');
    });
});

Running Tests

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.

Install Jest

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

Documentation

Documentation is hosted at frisbyjs.com, the documentation pages has separate repository.

License

Licensed under the BSD 3-Clause license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].