1.0.3 • Published 4 years ago

mockable-api v1.0.3

Weekly downloads
63
License
ISC
Repository
github
Last release
4 years ago

Mockable

Mock your API with an API.

Get Started

With npm:

npm install mockable-api --save-dev

With yarn:

yarn add mockable-api --dev

Then, simply launch the server:

npm run mockable

Override default options:

DEBUG=false MOCKABLE_PORT=3001 npm run mockable

## Use with Cypress

Configure the url of your mockable server with an environment variable in your cypress.json file:

{
  "env": {
    "mockableUrl": "http://localhost:3001/_mock"
  }
}

Note: default url http://localhost:3001/_mock

startServerMock

Use it before each of your test. It ensures no mock is still pending.

  beforeEach(() => {
    cy.startServerMock()
  })

stopServerMock

Use it after each of your test. It cleans all active mocks. Also, it logs still active mocks before cleaning if you're indebug mode.

  afterEach(() => {
    cy.stopServerMock()
  })

mockRequest

Use it like cy.route command.

  cy.mockRequest({
      method: 'GET',
      url: '/api/user',
      status: 200,
      response: {
        username: 'johndoe'
      }
  })