javascript - 在 Supertest 上使用 PUT 方法

标签 javascript node.js testing supertest http-put

如何在 SuperTest 中使用 PUT 方法?我得到的只是“404 Not found”作为响应。

请求处理程序:

router.put('/', function (req, res) {
    res.type('json');

    FooResource(req.body, function () {
        res.send("{}");
    });
});

测试套件:

describe("PUT /foo/fii", function () {

    it("Respond with 200", function (done) {

        request(app)
            .put('/')
            .set('Accept', 'application/json')
            .expect(200, done);

    });
});

最佳答案

添加:

    it("Respond with 200", function (done) {

        request(app)
            .put('/')
            .send("{}")
            .expect(200)
            .end(function(err, res) {
                done();
            })

    });

现在可以用了(?)

关于javascript - 在 Supertest 上使用 PUT 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42608696/

相关文章:

javascript - Material-UI 应用栏自带边距

json - Passport 通过json发送错误

javascript - 使用 JQuery 提交简单表单并对必填字段进行限制?

javascript - 是否可以使构造函数属性分配列表变得更短?

node.js - 如何从移动应用程序中的私有(private) api 获取背景的即时变化?

node.js - nodejs 多线程 vs nodejs 单线程

ios - TestFlight iOS 应用程序中的 "Could not install app. The tester does not have access to this app."错误

php - 为具有一定程度随机化的方法编写单元测试

testing - 黑盒 QA 测试技巧

javascript - 如何防止点击时选择选项卡?