mocha - wait for a minute before executing test
up vote
0
down vote
favorite
I have a situation where the test needs to wait for a minute to execute. Tried below code but it doesn't work:
describe('/incidents/:incidentId/feedback', async function feedback() {
it('creates and update', async function updateIncident() {
// this works fine
});
// need to wait here for a minute before executing below test
it('check incident has no feedback', function checkFeedback(done){
setTimeout(function(){
const result = send({
user: 'Acme User',
url: `/incidents/${createdIncident.id}/feedback`,
method: 'get',
});
console.log(result);
expect(result.response.statusCode).to.equal(200);
expect(result.response.hasFeedback).to.equal(false);
done();
}, 1000*60*1);
});
});
Here, send()
returns Promise
. I tried with async await
but it didn't work.
How do I make test wait for a minute before executing ?
javascript node.js mocha
add a comment |
up vote
0
down vote
favorite
I have a situation where the test needs to wait for a minute to execute. Tried below code but it doesn't work:
describe('/incidents/:incidentId/feedback', async function feedback() {
it('creates and update', async function updateIncident() {
// this works fine
});
// need to wait here for a minute before executing below test
it('check incident has no feedback', function checkFeedback(done){
setTimeout(function(){
const result = send({
user: 'Acme User',
url: `/incidents/${createdIncident.id}/feedback`,
method: 'get',
});
console.log(result);
expect(result.response.statusCode).to.equal(200);
expect(result.response.hasFeedback).to.equal(false);
done();
}, 1000*60*1);
});
});
Here, send()
returns Promise
. I tried with async await
but it didn't work.
How do I make test wait for a minute before executing ?
javascript node.js mocha
If you are waiting on something to be updated from another test, you're doing it wrong.
– James
Nov 22 at 16:28
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a situation where the test needs to wait for a minute to execute. Tried below code but it doesn't work:
describe('/incidents/:incidentId/feedback', async function feedback() {
it('creates and update', async function updateIncident() {
// this works fine
});
// need to wait here for a minute before executing below test
it('check incident has no feedback', function checkFeedback(done){
setTimeout(function(){
const result = send({
user: 'Acme User',
url: `/incidents/${createdIncident.id}/feedback`,
method: 'get',
});
console.log(result);
expect(result.response.statusCode).to.equal(200);
expect(result.response.hasFeedback).to.equal(false);
done();
}, 1000*60*1);
});
});
Here, send()
returns Promise
. I tried with async await
but it didn't work.
How do I make test wait for a minute before executing ?
javascript node.js mocha
I have a situation where the test needs to wait for a minute to execute. Tried below code but it doesn't work:
describe('/incidents/:incidentId/feedback', async function feedback() {
it('creates and update', async function updateIncident() {
// this works fine
});
// need to wait here for a minute before executing below test
it('check incident has no feedback', function checkFeedback(done){
setTimeout(function(){
const result = send({
user: 'Acme User',
url: `/incidents/${createdIncident.id}/feedback`,
method: 'get',
});
console.log(result);
expect(result.response.statusCode).to.equal(200);
expect(result.response.hasFeedback).to.equal(false);
done();
}, 1000*60*1);
});
});
Here, send()
returns Promise
. I tried with async await
but it didn't work.
How do I make test wait for a minute before executing ?
javascript node.js mocha
javascript node.js mocha
asked Nov 22 at 15:39
Valay
85821658
85821658
If you are waiting on something to be updated from another test, you're doing it wrong.
– James
Nov 22 at 16:28
add a comment |
If you are waiting on something to be updated from another test, you're doing it wrong.
– James
Nov 22 at 16:28
If you are waiting on something to be updated from another test, you're doing it wrong.
– James
Nov 22 at 16:28
If you are waiting on something to be updated from another test, you're doing it wrong.
– James
Nov 22 at 16:28
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
If promises are used, they preferably shouldn't be mixed with plain callbacks.
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
...
it('check incident has no feedback', async function checkFeedback(){
this.timeout(1.33 * 60 * 1000);
await wait(1 * 60 * 1000);
const result = await send(...);
...
});
Tried this. it throws an errorError: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
.
– Valay
Nov 22 at 16:04
1
This is a different issue. This means that you need to increase a timeout before using such long delays. See for reference, stackoverflow.com/questions/15971167/…
– estus
Nov 22 at 16:22
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
If promises are used, they preferably shouldn't be mixed with plain callbacks.
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
...
it('check incident has no feedback', async function checkFeedback(){
this.timeout(1.33 * 60 * 1000);
await wait(1 * 60 * 1000);
const result = await send(...);
...
});
Tried this. it throws an errorError: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
.
– Valay
Nov 22 at 16:04
1
This is a different issue. This means that you need to increase a timeout before using such long delays. See for reference, stackoverflow.com/questions/15971167/…
– estus
Nov 22 at 16:22
add a comment |
up vote
2
down vote
accepted
If promises are used, they preferably shouldn't be mixed with plain callbacks.
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
...
it('check incident has no feedback', async function checkFeedback(){
this.timeout(1.33 * 60 * 1000);
await wait(1 * 60 * 1000);
const result = await send(...);
...
});
Tried this. it throws an errorError: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
.
– Valay
Nov 22 at 16:04
1
This is a different issue. This means that you need to increase a timeout before using such long delays. See for reference, stackoverflow.com/questions/15971167/…
– estus
Nov 22 at 16:22
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
If promises are used, they preferably shouldn't be mixed with plain callbacks.
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
...
it('check incident has no feedback', async function checkFeedback(){
this.timeout(1.33 * 60 * 1000);
await wait(1 * 60 * 1000);
const result = await send(...);
...
});
If promises are used, they preferably shouldn't be mixed with plain callbacks.
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
...
it('check incident has no feedback', async function checkFeedback(){
this.timeout(1.33 * 60 * 1000);
await wait(1 * 60 * 1000);
const result = await send(...);
...
});
edited Nov 22 at 16:22
answered Nov 22 at 15:49
estus
65.1k2195203
65.1k2195203
Tried this. it throws an errorError: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
.
– Valay
Nov 22 at 16:04
1
This is a different issue. This means that you need to increase a timeout before using such long delays. See for reference, stackoverflow.com/questions/15971167/…
– estus
Nov 22 at 16:22
add a comment |
Tried this. it throws an errorError: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
.
– Valay
Nov 22 at 16:04
1
This is a different issue. This means that you need to increase a timeout before using such long delays. See for reference, stackoverflow.com/questions/15971167/…
– estus
Nov 22 at 16:22
Tried this. it throws an error
Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
.– Valay
Nov 22 at 16:04
Tried this. it throws an error
Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
.– Valay
Nov 22 at 16:04
1
1
This is a different issue. This means that you need to increase a timeout before using such long delays. See for reference, stackoverflow.com/questions/15971167/…
– estus
Nov 22 at 16:22
This is a different issue. This means that you need to increase a timeout before using such long delays. See for reference, stackoverflow.com/questions/15971167/…
– estus
Nov 22 at 16:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434297%2fmocha-wait-for-a-minute-before-executing-test%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you are waiting on something to be updated from another test, you're doing it wrong.
– James
Nov 22 at 16:28