georoot georoot - 1 year ago 69
Node.js Question

Supertest shows passing when it should fail

Here is the output from morgan

::ffff: - - [01/Dec/2016:23:44:19 +0000] "GET /temp HTTP/1.1" 404 17 "-" "node-superagent/2.3.0"

And the tests that i have written are

var chai = require("chai");
var request = require('supertest');
var server = require("../app");

describe("Basic tests", function() {
describe("Check if server is running", function() {
it("Root endpoint returns 200", function() {

is showing
code that i can also confirm by passing a function in
but the test are running fine in mocha with no errors. Where am i going wrong ?

Answer Source

The problem is that the test is async and mocha assumes that, if you don't return a promise from your test or specify a callback function, your test is synchronous (more info here).

So, add a callback function.

it("Root endpoint returns 200", function(done) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download