idiot on ruby idiot on ruby - 1 year ago 87
Node.js Question

How to store the response body for further test case in supertest

I have an API /user/login which returns the token.

using supertest and mocha i wrote a test case where it will make a call to '/user/login' and verify that the response has a token or not

now i have to store the token for further token for further test case

How can i achieve that

Answer Source

I hope this example will help you.

describe("Example with token", function () {
  let token;

  before(function (done) {
    //getting token logic
    token = tokenValue;

  it("first test", function (done) {
      .set("TokenHeader", token)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download