0

I'm building an API and I'm trying to test it with mocha and supertest.

I'm correctly testing a POST call with this code:

it("Should generate a PDF based on the given data using API", function(done) {

    request(app)
    .post("/api/document/print")
    .send({tplName: "default", tplData: { title: "Testee", p1: "paragraph"}})
    .expect(200, done);

});

But when I try to test a GET request with this code:

it("Should get HTML of the selected template", function(done) {

    request(app)
    .get("/api/template/default/html")
    .expect(200, done);

});

The test fails, if I run my app and try it in Chrome I get the correct response (200).

What am I doing wrong?

Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160

1 Answers1

0

Are these tests in the same file? Within the same describe block? Perhaps you could try this:

.expect(200) .end(function(err, res){ if (err) return done(err); done() });

Yousef
  • 401
  • 2
  • 8