I am writing unit test cases to test methods of user.service.js inside user.test.js but I am getting this error if the number of test cases increases: "Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves."
Here I am attaching plunker link to minimum required files:
https://plnkr.co/edit/3us5ja?p=info
describe('testing', function() {
describe('random test cases 1', function() {
it('Get all contacts 1', function() {
return contactService.getAll((result) => {
//console.log('all contact data: ' +
JSON.stringify(result));
});
});
it('Get all contacts 2', function() {
return contactService.getAll((result) => {
//console.log('all contact data: ' + JSON.stringify(result));
});
});
it('Get all contacts 3', function() {
return contactService.getAll((result) => {
//console.log('all contact data: ' + JSON.stringify(result));
});
});
});
describe('random test cases 2', function() {
it('Get all contacts 21', function() {
return contactService.getAll((result) => {
//console.log('all contact data: ' + JSON.stringify(result));
});
});
it('Get all contacts 22', function() {
return contactService.getAll((result) => {
//console.log('all contact data: ' + JSON.stringify(result));
});
});
it('Get all contacts23', function() {
return contactService.getAll((result) => {
//console.log('all contact data: ' + JSON.stringify(result));
});
});
});
describe('random test cases 3', function() {
it('Get all contacts 31', function() {
return contactService.getAll((result) => {
//console.log('all contact data: ' + JSON.stringify(result));
});
});
it('Get all contacts 32', function() {
return contactService.getAll((result) => {
//console.log('all contact data: ' + JSON.stringify(result));
});
});
it('Get all contacts 33', function() {
return contactService.getAll((result) => {
//console.log('all contact data: ' + JSON.stringify(result));
});
});
});
});
Some of the files are not relevant here. The things what I had tried is:
1) overrided timeout for all the test cases and facing the same issue after few test case.
2) called done() in every test cases.
3) configured timeout in described, it, command line also in package.json.
I am returning promises from DAO. So when promise got resolve we can't predict. And order of test cases also we can't predict so we can't increase timeout also for test suite or individual test cases. There are few more test cases for other services also. So, is there any way to fix this issue.
This usually means that the test has not called done() in it's successful state. You can fix this by calling done().
describe('testing', () => {
describe('random test cases 1', () => {
it('Gets all contacts 1', (done) => {
return contactService.getAll((result) => {
done();
});
});
it('Gets all contacts 2', (done) => {
return contactService.getAll((result) => {
done();
});
});
});
describe('random test cases 2', () => {
it('Gets all contacts 21', (done) => {
return contactService.getAll((result) => {
done();
});
});
it('Gets all contacts 22', (done) => {
return contactService.getAll((result) => {
done();
});
});
});
});
If you are still seeing the error it's probably that the callback is not being invoked, doublecheck the async function, e.g. contactService.getAll() above. Read also https://mochajs.org/#asynchronous-code carefully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With