Reputation: 790
I am trying to increase the timeout for mocha tests as they are web requests that form part of an automated UI test suite and therefore can take longer than the default 2000ms.
The code itself works great if I call mocha with the --timeout set to 5000ms or so but the default 2000ms is not enough.
I want to be able to set the timeout per test suite so that the timeout becomes part of the success criteria which might be different on a case by case basis.
before(()=>{
var sw = require('selenium-webdriver');
this.driver = new sw.Builder().withCapabilities(sw.Capabilities.chrome()).build();
var c = require('chai');
c.use(require('chai-webdriver')(this.driver));
this.expect = c.expect;
return this.driver.getWindowHandle();
})
after(() => {
return this.driver.quit();
})
describe('Looking at github', () => {
beforeEach(() => {
this.driver.get('http://stackoverflow.com/');
})
describe('When we take a look at the stack overflow home page', () => {
return it('It does not have crazy cat text in it!', () => {
return this.expect('#h-top-questions').dom.to.not.contain.text("Just cats here!");
});
});
})
Upvotes: 12
Views: 5340
Reputation: 667
An alternative to basarat's answer, along similar lines that uses different syntax (that is effectively confusing in a different way!):
describe('When we take a look at the stack overflow home page', () => {
it('does not have crazy cat text in it!', () => {
expect('#h-top-questions').dom.to.not.contain.text("Just cats here!");
}).timeout(5000);
});
Upvotes: 6
Reputation: 275927
Use function
intead of an arrow
and then just call this.timeout(5000);
e.g.
describe('When we take a look at the stack overflow home page', () => {
return it('It does not have crazy cat text in it!', function() {
this.timeout(5000);
return this.expect('#h-top-questions').dom.to.not.contain.text("Just cats here!");
});
});
This is because ()=>
captures the surrounding this
. More http://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html
Upvotes: 27