express-api-test

1.1.0 • Public • Published

express-api-test

Fast unit testing for express.js 4.x APIs

Build Status

it('should respond with Hello <name>', () => {
  return new ApiTest(api.sayHello)
    .setParams({ name: 'John' })
    .expectStatus(200)
    .expectSend('Hello John')
    .run()
})

Testing express.js APIs is Easy Peasy with express-api-test

  • No need to fiddle with req/res mocks.
  • No need to write boilerplate asserts
  • No need to start http server, lightning-fast tests
  • Fluent-interface: helps with IDE auto-suggestions
  • Easily readable tests, easier to maintain
  • Will cover all the express.js request and response parameters and methods soon!

API Documentation

ApiTest documentation

Installation

$ npm i -g npm
$ npm i --save-dev express-api-test

Usage

Examples:

const ApiTest = require('express-api-test')
 
describe('Food API', () => {
  describe('getFood', () => {
    it('should respond with Potato', () => {
      return new ApiTest(api.getFood)
        .setParams({ name: 'Potato', amount: 5 })
        .expectStatus(200)
        .expectJson({ food: 'Potato x 5'})
        .run()
    })
  })
})

You can use express-api-test with node-swagger APIs, instead of using setParams, use setSwaggerParams. Example:

const ApiTest = require('express-api-test')
 
describe('Swagger Fruit API', () => {
  describe('getFruitBasket', () => {
    it('should respond with Carrot', () => {
      return new ApiTest(api.getFruitBasket)
        .setSwaggerParams({ name: 'Apple', amount: 10 })
        .expectStatus(200)
        .expectJson({ fruitBasket: 'Apple x 10'})
        .run()
    })
  })
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    1
    • latest

Version History

Package Sidebar

Install

npm i express-api-test

Weekly Downloads

1

Version

1.1.0

License

ISC

Unpacked Size

41.9 kB

Total Files

4

Last publish

Collaborators

  • abitwise