mockyeah ![Build Status](https://travis-ci.org/ryanricard/mockyeah.svg)
"A powerful service mocking, recording, and playback utility."
Testing is difficult when you don't have control of your data. mockyeah puts you in complete control, enabling you to implement real mock web services with ease. Real mock services means you have control of response payloads, HTTP Status Codes, response latency, and more.
Have a requirement to implement specific behavior when a service is slow to respond or a server returns an unexpected status code? No problem! mockyeah makes developing for such requirements easy.
Install
$ npm install mockyeah --save-dev
Usage
API
CLI
Introductory tutorial
-
Create an example project and initialized with NPM
$ mkdir example-app && cd example-app
$ npm init
-
Install mockyeah
$ npm install mockyeah --save-dev
-
Create script file and add the source below
$ touch index.js
const mockyeah = require('mockyeah');
mockyeah.get('/hello-world', { text: 'Hello World' });
-
Run the script file with Node
$ node index.js
-
Open http://localhost:4001/hello-world
-
Profit. You should see "Hello World" returned from your mock server.
Testing with mockyeah
const request = require('supertest')('http://localhost:4001');
const mockyeah = require('mockyeah');
describe('Wondrous service', () => {
afterEach(() => mockyeah.reset());
after(() => mockyeah.close());
it('should create a mock service that returns an internal error', (done) => {
mockyeah.get('/wondrous', { status: 500 });
request
.get('/wondrous')
.expect(500, done);
});
it('should create a mock service that returns JSON', (done) => {
mockyeah.get('/wondrous', { json: { foo: 'bar' } });
request
.get('/wondrous')
.expect(200, { foo: 'bar' }, done);
});
it('should verify a mock service expectation', (done) => {
const expectation = mockyeah
.get('/wondrous', { text: 'it worked' })
.expect()
.params({
foo: 'bar'
})
.once();
request
.get('/wondrous?foo=bar')
.expect(200, 'it worked')
.then(() => {
expectation.verify();
done();
});
});
});