Friday, 5 May 2017

How to wait for an assignment before moving on to rest of the testing with mocha/chai?

I'm a JS beginner learning to test express server.

....
const server = app.listen(process.env.PORT || 9000, () =>
{
    console.log("Started listening on port", server.address().port);
});

module.exports.server = server;

test:

const assert = require('chai').assert;
const request = require('supertest');

const server;

describe("index.js", () =>
{
    before(() =>
    {
        server = require('../index').server;
    });

    it("responds to /", (done) =>
    {
        console.log(server);// undefined
    ....

My guess is that it("responds to /", ... begins to test before server variable has been assigned. I know done is used for async, but I could not find out how to use it for an assignment. How could I ensure it check happens after server has been assigned?



via Robert C. Holland

No comments:

Post a Comment