I'm running an Express Node server, and using Mocha and Supertest to test my routes.
I would like to be able to test for the existence of certain text in the response for one of my Express routes, as so:
it('should display form text input', function(done) {
request(app)
.get('/')
.end(function (err, res) {
if (err) {
return done(err);
}
res.text.should.include('class="text-input-wname');
done();
});
});
However, when I run this test, I get the following error:
Uncaught TypeError: undefined is not a function
The res.text prints out fine to the console. I know that should.include() is meant to check for the existence of an element in an array, so presumed this might not work.
But what is the correct way to parse the response body to check for the existence of some text?
Have you tried it with the match
-assertion, like:
res.text.should.match(/class="text-input-wname/)