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?
No comments:
Post a Comment