I have the following test code in NodeJS:
'use strict';
// Example class to be tested
class AuthController {
constructor() {
console.log('Auth Controller test!');
}
isAuthorizedAsync(roles, neededRole) {
return new Promise((resolve, reject) => {
return resolve(roles.indexOf(neededRole) >= 0);
});
}
}
module.exports = AuthController;
And the following mocha test code:
'use strict';
const assert = require('assert');
const AuthController = require('../../lib/controllers/auth.controller');
describe('isAuthorizedAsync', () => {
let authController = null;
beforeEach(done => {
authController = new AuthController();
done();
});
it('Should return false if not authorized', function(done) {
this.timeout(10000);
authController.isAuthorizedAsync(['user'], 'admin')
.then(isAuth => {
assert.equal(true, isAuth);
done();
})
.catch(err => {
throw(err);
done();
});
});
});
which throws the following error:
1 failing
1) AuthController
isAuthorizedAsync
Should return false if not authorized:
Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (c:\supportal\node_modules\ttm-module\test\controllers\auth.controller.spec.js)
I have tried increasing the default mocha test timeout to 10secs and made sure that the promise resolves. I am new to mocha. Am I missing something here?