superAgent support await / async

superAgent support await / async

http://visionmedia.github.io/superagent/

From superAgent 2.0 version, it adapt Promise, so we can use await, async in current request.

SuperAgent's request is a "thenable" object that's compatible with JavaScript promises and async/await syntax.  

Also, superTest has superAgent as onne of dependencies. Now superTest upgrade dependencies, we can directly use superAgent 2.0 await async feature in test case.

code example

await / async style

let response = await request(app)  
                  .post('/v1/sessions')
                  .set('Accept','application/json')
                  .send({"email": "[email protected]", "password": "123"});
console.log(response);  

old style

request(app)  
  .post('/v1/sessions')
  .set('Accept','application/json')
  .send({"email": "[email protected]", "password": "123"})
  .end(function (err, res) {
      console.log(res);
  });

CaesarChi

Web developer, focus on website fullstack, special JavaScript, and love sharing developing experience and communicate with developers. http://about.me/clonn