chai expect(res.body) fails consistently


Please briefly explain why you feel this question should be reported .

Report Cancel

Response status passes and fails under my control. But I can’t see to get the expect(res.body) test to pass. Route displays exactly as programmed when viewed in the browser. but mocha/chai test for testing what is rendered in the browser always fails. What am I doing wrong??
health-check route code:

import express from 'express';
const router = express.Router();   // eslint-disable-line new cap
// GET /health-check - checking for basic server reaction
router.get('/health-check', (req, res) =>
export default router;

mocha test:

it('should return 200 and res.body of OK', (done) => {
            .end(function(err, res) {
                    return done(err);
                return done();

solved 0
1 Answer 15 views 0

Answer ( 1 )

    January 11, 2017 at 6:00 pm

    Please briefly explain why you feel this answer should be reported .

    Report Cancel

    Ok, I figured it out. I had to console log the response and then dive into that until I got it to respond correctly. In my sameple above, it was returning an empty set or null. My code that tends to answer my issue is:

    .end(function(err, res) {
             return done(err);
          return done();

    my original idea was that I had to target the “.body” of the response to test against it. Doesn’t appear to be the case here.

    Best answer

Leave an answer


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>