How to chain http calls with superagent/supertest?

后端 未结 4 1805
一个人的身影
一个人的身影 2021-02-01 13:28

I am testing an express API with supertest.

I couldn\'t get multiple requests in a test case to work with supertest. Below is what i tried in a test case. But the test c

4条回答
  •  一生所求
    2021-02-01 14:09

    Tried to put this in a comment above, formatting wasn't working out.

    I'm using async, which is really standard and works really well.

    it('should respond to only certain methods', function(done) {
        async.series([
            function(cb) { request(app).get('/').expect(404, cb); },
            function(cb) { request(app).get('/new').expect(200, cb); },
            function(cb) { request(app).post('/').send({prop1: 'new'}).expect(404, cb); },
            function(cb) { request(app).get('/0').expect(200, cb); },
            function(cb) { request(app).get('/0/edit').expect(404, cb); },
            function(cb) { request(app).put('/0').send({prop1: 'new value'}).expect(404, cb); },
            function(cb) { request(app).delete('/0').expect(404, cb); },
        ], done);
    });
    

提交回复
热议问题