If I'm testing a koa/express app with Jest and supertest, how can I mock the functions of deeply nested dependencies?The only require in the test file below is app, but nothing in app needs to be mocked. app requires route which requires data which requires api, and I'd like to mock api.getValues() to return some specific data or throw an error.I can't get it to work though using the Jest documentation on mocks, I think it's because of the nested dependencies. Do you know how I can do it? test('check someRoute', async () => { const response = await request(app) .post('/someRoute') .type('form') .send({ key: 'value', }) expect(response.status).toBe(200) })
Submitted February 02, 2018 at 05:20PM by nowboarding
No comments:
Post a Comment