sách gpt4 ăn đã đi

javascript - Mocha/应该 'undefined is not a function'

In lại Tác giả: Walker 123 更新时间:2023-11-30 16:28:30 29 4
mua khóa gpt4 giày nike

我要离开 cái này教程,尝试使用 Mocha、Supertest 和 Should.js 进行测试。

我有以下基本测试来通过 PUT 创建用户接受 header 中数据的端点。

describe('User Routes', function () {
it('should allow me to make my user', function (done) {
request(url)
.put('/users')
.set(myCreds)
// end handles the response
.end(function(err, res) {
if (err) {
throw err;
}
// this is should.js syntax, very clear
res.should.have.status(201);
done();
});
});

然而,虽然端点确实触发了,并且用户确实成功了,但代码会抛出一个错误 should未定义... Uncaught TypeError: undefined is not a function .

我有

var should = require('should');
var assert = require('assert');
var request = require('supertest');

在文件的顶部,为什么它是未定义的?

câu trả lời hay nhất

你打错了,试试这个:

res.should.have.property('status', 201)

hoặc

res.status.should.be.equal(201)

hoặc

should.equal(res.status, 201)

或安装 should-http .

关于javascript - Mocha/应该 'undefined is not a function',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33726670/

29 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress