Closed paztis closed 3 months ago
You can access the data returned with res.json.mock.calls[0][0]
You can access the data returned with
res.json.mock.calls[0][0]
This does not work:
import handler from './handler';
describe('Basic express test example', () => {
it('returns pong', async () => {
const req = getMockReq();
const { res } = getMockRes();
await handler.ping(req, res); // (_, res) => res.send('pong');
const response = res.json.mock.calls[0][0] // is empty array
expect(response).toBe("pong");
});
});
Closing this now as it's gone stale and an answer has been provided.
currently the only way to test the data is to call
I may be important to store the data in you mock to let it be accessed with expect(res.data).toBe(...)
It may be done in your mock by saving the args of the send / josn / end