ynn-mock
Mocking data for Ynn
Installation
$ npm i --save-dev ynn-mock
Usage
mock.rsc
Mocking data for RSC request for test cases.
mock.rsc( app, uri, response )
mock.rsc( app, response )
mock.rsc.restore( app )
const mock = require( 'ynn-mock' );
const app = new Ynn( {
root : __dirname,
debugging : false,
logging : false
} );
describe( 'Ynn test', () => {
beforeAll( async () => {
await app.ready();
await mock.rsc( app, 'service:the/api', { n : 1 } );
await mock.rsc( app, { n : 2 } );
} );
afterAll( () => mock.rsc.restore( app ) );
it( 'should use mock response for "service:the/api"', async () => {
const res = app.rsc.call( 'service:the/api' );
expect( res ).toEqual( { n : 1 } );
} );
it( 'should use mock response which does not specify an URI', async () => {
const res = app.rsc.call( 'api/that/is/not/mock' );
expect( res ).toEqual( { n : 2 } );
} );
} );
mock.service
const mock = require( 'ynn-mock' );
describe( 'mock.service', () => {
it( 'desc', async () => {
const app = new Ynn( {
root : __dirname,
debugging : true,
logging : false
} );
await mock.service( app, 'serviceName', {
property1 : value,
property2 : value
...
} )
} );
} );