In the following helloWorld.test.ts
I can't get access to res.text
to test the HTML result:
import * as chai from 'chai';
import chaiHttp = require('chai-http');
import app from '../src/App';
chai.use(chaiHttp);
const expect = chai.expect;
describe('baseRoute', () => {
it('should be html', async () => {
const res = await chai.request(app).get('/');
expect(res.type).to.eql('text/html');
});
it('should have the message in body', async () => {
const res = await chai.request(app).get('/');
//console.log("Result:", res);
expect(res.text).to.eql('<html><head><title>Hey</title></head><body><h1>Hello world!</h1></body></html>');
});
});
When I try to build my project in VSCode, I get a Property 'text' does not exist on type 'Response'.
error, which is consistent with the autocompletion that only shows three properties for a Response
: body
, status
, and type
.
The res.body
is always {}
so, according to the answer to the following question, one should use res.text
(in JavaScript): Chai response.body is always empty {}
How to get access in TypeScript to res.text
?