0

After I add app.use(flash()) to user express-flash, supertest does not work with any route in my app that calls res.render(). The test just times out, it doesn't execute the end or expect callbacks.

Static routes and routes that just call res.send work as expected.

In the browser my app works perfectly for all routes.

I started listening to the res.render callback to make sure there wasn't a rendering error, and the callback is called just fine during tests with the correct rendered template.

What can be causing the test to timeout?

Here is an example route I set, which doesn't work.

 app.get("/test", (req, res) => res.render("dashboard"));

And here is my spec:

it("at least returns something", (done) => {
            request(app)
                .get("/test")
                .expect(200)
                .end(err =>
                  err
                    ? done.fail(err)
                    : done()
                );
        });
Marcelo Lazaroni
  • 9,819
  • 3
  • 35
  • 41

1 Answers1

0

Well, in the end the problem was that my session store was on MongoDB, and because I was mocking Mongo, it would never get a connection, therefore it would hang.

Here is the culprit.

const session = expressSession({
    secret: "double rainbow",
    store: new MongoStore({ mongooseConnection: database.getConnection() }),
    resave: false,
    saveUninitialized: false
});

I ended up moving this MongoStore creation to another module and mocking it during tests.

Marcelo Lazaroni
  • 9,819
  • 3
  • 35
  • 41