Express 带有笑话和超级测试的测试响应体

Express 带有笑话和超级测试的测试响应体,express,jestjs,supertest,Express,Jestjs,Supertest,我有一个简单的express http服务器,在发出get-to命令时返回“Hello-worl”/ 我有以下测试: import request from 'supertest'; import app from '../app/app'; test('test http server', async () => { const res = await request(app).get('/') expect(res.body).toEqual('Hello world');

我有一个简单的express http服务器,在发出get-to命令时返回“Hello-worl”/

我有以下测试:

import request from 'supertest';
import app from '../app/app';

test('test http server', async () => {
  const res = await request(app).get('/')
  expect(res.body).toEqual('Hello world');
});
测试失败的原因如下:

● test http server
expect(received).toEqual(expected)
Expected: "Hello world"
Received: {}
   7 |   const res = await request(app).get('/')
   8 | 
>  9 |   expect(res.body).toEqual('Hello world');

我如何才能将response.body作为文本来检查它?

然后似乎只返回文本(没有json),您可以使用
res.text
,如下所示:

● test http server
expect(received).toEqual(expected)
Expected: "Hello world"
Received: {}
   7 |   const res = await request(app).get('/')
   8 | 
>  9 |   expect(res.body).toEqual('Hello world');
test('testhttp服务器',async()=>{
const res:request.Response=等待请求(app.get)(“/”)
expect(res.type).toEqual('text/html');
expect(res.text).toEqual(“你好世界”);
});
另一方面,在测试返回json的端点时,我可以这样做:

● test http server
expect(received).toEqual(expected)
Expected: "Hello world"
Received: {}
   7 |   const res = await request(app).get('/')
   8 | 
>  9 |   expect(res.body).toEqual('Hello world');
test('test valid\u cuit with a valid case',async()=>{
常量提示:字符串='20-24963205-9'
const res:request.Response=wait request(app.get)(`/api/valid\u cuit/${cuit}`)
expect(res.type).toEqual('application/json'))
expect(res.body.cuit).toEqual(cuit)
expect(res.body.isValid).toBe(true)
});