Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous test in mocha #295

Open
silvae86 opened this issue Nov 24, 2017 · 1 comment
Open

Asynchronous test in mocha #295

silvae86 opened this issue Nov 24, 2017 · 1 comment

Comments

@silvae86
Copy link
Member

All assertions inside the HTTP call callbacks need to be wrapped in try-catch blocks that call done(error), because at this time if there is a

res.status.should.equal(200)

inside a callback for a REST api call, the whole test suite will die. If we catch the error and call done(error), only the failed test case will be failed and others will continue.

Example:

OK

createProjectsUnit.setup(function (err, res)
        {
            try{
                should.equal(err, null);
            }
            catch(e)
            {
                done(err);
            }
        });

NOT OK

createProjectsUnit.setup(function (err, res)
        {
            should.equal(err, null); // this will throw an uncaught Error, effectively crashing the test suite before calling done().
            done();
        });
silvae86 added a commit that referenced this issue Nov 24, 2017
Removed test assertions in units
Added a try-catch to administer tests
In the future we need to fix all callbacks: Issue: #295
@silvae86
Copy link
Member Author

silvae86 commented Nov 26, 2017

Found a good alternative, niftylettuce/check-chai, allows you to do this:

            chai.check(done, function ()
            {
                should.equal(err, null);
            });

We need to write a piece of code to make the replacements on our tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant