Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SuperTest's expect vs. Chai.expect

I'm confused, so if I use SuperTest which apparently looks like it has its own expect assertion, then I don't need to worry about using Chai? Or when I require Chai, Supertest knows about it and is using it as the expect mechanism?

like image 848
PositiveGuy Avatar asked Jul 07 '15 19:07

PositiveGuy


1 Answers

SuperTest extends SuperAgent's request object to include an expect function. It doesn't work quite like Chai's expect assertion, but can be used to assert the http response status and headers, and can be mixed with Chai's expect.

request(app).
get('/').
expect(200).    // request.expect, is status code 200?
expect('Content-Type', /json/).    // request.expect, does content-type match regex /json/?
expect(function(res){  // request.expect, does this user-provided function throw?
  // user-provided function can include Chai assertions
  expect(res.body).to.exist;
  expect(res.body).to.have.property('status');
}).
end(done);
like image 200
pmcoltrane Avatar answered Sep 20 '22 04:09

pmcoltrane