done() called within superagent request not working

270
September 04, 2017, at 3:39 PM

I am creating an app with a feature to post on login. I have written the following test code in mocha. I get this error:

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

I think I made some mistake in using done(). All other assert statements have passed. Let me know where I am going wrong, or if if you need more info.

it("Login and post", function(done) {
    superagent
        .post(URL_ROOT + "/register")
        .send({
            email: "posttest@test.com",
            password: "posttest"
        })
        .end(function(err, res) {
            assert.ifError(err);
            var token = res.body.token;
            superagent
                .post(URL_ROOT + "/post")
                .send({
                    content: "testing post",
                    user: jwt.decode(token).id
                })
                .set("Authorization", "test_scheme " + token)
                .end(function(err, res){
                    assert.ifError(err);
                    assert.equal(res.body.post.content, "testing post");
                    done();
                });
        });
});
Answer 1

Your test might be taking more than 2 seconds to run: In the first line of your callback to it, right before superagent .post(URL_ROOT + "/register")... add this line:

this.timeout(30000)

This allows your to only time out after 30 seconds instead of 2.

Rent Charter Buses Company
READ ALSO
Loading an mp4 file from MongoDB using Objective C

Loading an mp4 file from MongoDB using Objective C

I have a nodejs server which successfully saves mp4 files to my MongoDB

444
error in installing npm

error in installing npm

I wanted to clean wipe the npm and node from my system (linux mint) & reinstall themWhile installing the back, I'm facing a typical error

350
process.argv shows empty for babel transpiled codes

process.argv shows empty for babel transpiled codes

I am trying to achieve es2015 features on "node version 84

280
Webpack, sass-loader (or css-loader) nested file imports inside node_modules. File not found

Webpack, sass-loader (or css-loader) nested file imports inside node_modules. File not found

I want to use primercss framework as sassI am using webpack to build my application

439