繁体   English   中英

在Supertest上使用PUT方法

[英]Using PUT method on Supertest

如何在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();
            })

    });

现在它有效(?)

让我在这里分享一个使用promises的例子,它不需要done()

describe('PUT: update task (id:5)', function() {
    test('It should return response 200.', function() {
        return request(app)
            .put('/api/v1.0/tasks/5')
            .send({title:'Code Refactor API',user:'ivanleoncz'})
            .expect(200);
    });
});

有关更多信息: https//www.npmjs.com/package/supertest

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM