Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ensure the done() callback is being called in this test (Mocha, Chai, Sinon)

Looking at other questions, can't really find the cause of the problem. I am trying to import a module and test it using mocha.

import chai, {
    expect
}
from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import System from 'systemjs';
import '../public/config.js';

chai.use(sinonChai);

describe('helperModule', () => {
    let module;

    before(function () {
        return System.import('./public/js/helper.js')
            .then((mod) => module = mod);
    });

    describe('Module loading', function () {
        it('should load', function(){
            expect(module.default).to.not.be.undefined;
        });
    });
});

I get the following error when running the npm test command.

1) helperModule "before all" hook:
     Error: timeout of 2000ms exceeded. Ensure the done() callback is being
 called in this test.

Not really sure where to put the done callback. If you need any extra information about any packages I am using I will edit my question with them.

like image 596
Mihai Neagoe Avatar asked Dec 25 '22 08:12

Mihai Neagoe


1 Answers

There's an expectation that a done() callback is called when your test is complete. Some libraries do this implicitly for you, and you can also pass done to other functions that will call it on success. If you need to do it manually, done can be specified as a parameter of your test function to be called later.

describe('Module loading', function () {
    it('should load', function(done){
        expect(module.default).to.not.be.undefined;
        done();
    });
});
like image 187
tschaible Avatar answered Feb 16 '23 00:02

tschaible