Friday, 15 January 2010

node.js - Node js supertest is async? -


I want to write some tests for some routes and I want to do something like this:

 < Code> var = requires ('should'); Var app = requires ('../../app'); Var Requests = Required ('Superstest'); Describe ('Create and verify that creation is successful', function () {var user_id = ''; ('Add a new case and return a Jason array', function (done) {var newUser = {nume : '(' / Api / new_user ') .end (newUser) .expect (201) .expect (' content-type ', / json / test),' test ', varsta: 23} request (app).). Und (function (fault, leakage) {if (mistake) was returned (mistake); res.body.should.be.instanceOf (array); res.body.should.have.property ('_ id'); user_id = Res.body._id; done ();});}); ('New user should be back', function (done) {request (app) .get ('/ api / new_user /' + user_id) hope (200). Hope ('content-type', / json /) .end (function (error, ridge) {if (err) return done (err); res.body.should.be.instanceOf (object); Res.body._id.should.be.exactly (user_id); done ( );});});});  

I am not sure that two statements are executed after each other or each is assinked and when I go to the other, it is not executed first So it will fail because the insert was not done in the server. Should I use async.series?

Supertest in your example is responsible for the series from the request (app) Below, it is actually the provider of description () and this () call, which determines the order, or lacks it, in which your tests are executed In which I'm fine?

If yes, then Mocha will run your testcosms in sequence (as the second, which is already completed, will be called second).


No comments:

Post a Comment