Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ynnjs/ynn-mock

Mocking data for Ynn
https://github.com/ynnjs/ynn-mock

Last synced: 25 days ago
JSON representation

Mocking data for Ynn

Awesome Lists containing this project

README

        

# ynn-mock

Mocking data for Ynn

## Installation

```sh
$ 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 )**

```js
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 } );

// To mock response data for all URIs.
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 } ); // pass
} );

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 } ); // pass
} );
} );
```

### mock.service

```js
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
...
} )

} );
} );
```