The*_*pes 4 mocha.js node.js express supertest
我正在运行一个Express Node服务器,并使用Mocha和Supertest来测试我的路由.
我希望能够测试我的一条Express路线的响应中是否存在某些文本,如下所示:
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();
});
});
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此测试时,我收到以下错误:
Uncaught TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)
res.text打印出很好的控制台.我知道should.include()是为了检查数组中是否存在元素,所以假定这可能不起作用.
但是,解析响应主体以检查某些文本是否存在的正确方法是什么?