test responsebody with Jest and supertest
it seems like then returning only text (no json) you have yo use res.text
, like this:
test('test http server', async () => { const res: request.Response = await request(app).get('/') expect(res.type).toEqual('text/html'); expect(res.text).toEqual('Hello world');});
On the other hand, when testing an endpoint that returns json I can do like this:
test('test valid_cuit with a valid case', async () => { const cuit: string = '20-24963205-9' const res: request.Response = await request(app).get(`/api/valid_cuit/${ cuit }`) expect(res.type).toEqual('application/json') expect(res.body.cuit).toEqual(cuit) expect(res.body.isValid).toBe(true)});