Mock your API with an API.
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
Use it before each of your test. It ensures no mock is still pending.
beforeEach(() => {
cy.startServerMock()
})
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()
})
Use it like cy.route
command.
cy.mockRequest({
method: 'GET',
url: '/api/user',
status: 200,
response: {
username: 'johndoe'
}
})