🚀 Feature: Allow to set timeout on before/after/beforeEach/afterEach in declaration
Feature Request Checklist
- [X] I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
- [X] I have searched for related issues and issues with the
faqlabel, but none matched my issue. - [ ] I want to provide a PR to resolve this
Overview
it returns a TestFunction that has a timeout method. This is useful for setting timeouts in slow tests, without needing to define the test code inside a function() {} block.
An analogous feature would be useful for the before/beforeEach/after/afterEach hooks. The current workaround would be:
before(function() {
this.timeout(3000);
});
Suggested Solution
before/beforeEach/after/afterEach could return a HookFunction, analogous to TestFunction, which has a timeout method. The code above could be rewritten:
before(() => {}).timeout(3000);
Alternatives
None
Additional Info
No response
👍 Agreed, I'm surprised they didn't have this already! This took me a bit to parse through as someone who doesn't use those APIs much. Putting a summary here for clarity...
There are two ways to describe a timeout:
this.timeout(...);: allowed for hooks (before(...), etc.) as well as tests (it(...), etc.)- test.timeout(...): only allowed for tests
Assuming I'm understanding correctly, this issue is asking to allow hook.timeout(...). Doing so would mirror the test.timeout(...) already allowed.
@JoshuaKGoldberg thanks for summarizing it more clearly than the original post 🙂
ok, I just looked into the codebase, and I think this will be very simple to implement, but I am not sure about potential implications. I will send a PR shortly