atv-mock-api-util
v1.0.0
Published
```js const mocks = { 'get /api/message': { message: 'hello' }, 'post /api/model/:id': (req, res) => { res.send({ id: req.params.id }); } };
Downloads
1
Readme
mock-api-util
const mocks = {
'get /api/message': { message: 'hello' },
'post /api/model/:id': (req, res) => {
res.send({ id: req.params.id });
}
};
const { registMocks, executeMock } = require('@jiasuyunkeji-fe/mock-api-util');
// 注册 mocks
registMocks(mocks)
// 执行 mock
executeMock('/api/message', { method: 'get' }) // [ture, { body: mocks['get /api/message'] }]
executeMock('/api/message', { method: 'post' }) // [false]
executeMock('/api/model/1', { method: 'post' }) // [true, { body: { id: '1' }, status: 200, headers: {} }]