上QQ阅读APP看书,第一时间看更新
Making the POST requests via supertest
We're going to call request, passing in the app we want to make the request on. Next up, we're going to call .post, which sets up a POST request. We're going to go to /todos, and the new thing we're going to do is actually send data. In order to send data along with the request as the body we have to call send, and we're going to pass in an object. This object is going to get converted to JSON by supertest, so there's no need for us to worry about that—just another great reason to use the supertest library. We're going to set text equal to the text variable shown previously, and we can use the ES6 syntax to get that done:
describe('POST /todos', () => { it('should create a new todo',(done) => { var text = 'Test todo text'; request(app) .post('/todos') .send({text}) }) });
Now that we've sent the request, we can start making assertions about the request.