Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,23 @@ class Suite extends EventEmitter {
// Allow overriding inner/nested suites
// See and test-cases with chain-called timeout argument.
// https://github.com/mochajs/mocha/issues/5422
// https://github.com/mochajs/mocha/issues/6033
for (const t of this.tests) {
t.timeout(this._timeout);
}
for (const s of this.suites) {
s.timeout(this._timeout);
}
for (const hooks of [
this._beforeAll,
this._beforeEach,
this._afterAll,
this._afterEach,
]) {
for (const h of hooks) {
h.timeout(this._timeout);
}
}
return this;
}

Expand Down
18 changes: 18 additions & 0 deletions test/unit/suite.spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ describe("Suite", function () {
const newSuite = suite.timeout(5000);
expect(newSuite.timeout(), "to be", 5000);
});

it("should propagate the timeout to already-registered hooks", function () {
// https://github.com/mochajs/mocha/issues/6033
// The chained `describe(...).timeout(N)` form creates hooks during the
// describe callback (with the suite's default timeout) and only calls
// the setter afterwards, so the new value must reach the hook arrays.
suite.beforeAll(function () {});
suite.beforeEach(function () {});
suite.afterAll(function () {});
suite.afterEach(function () {});

suite.timeout(5000);

expect(suite.getHooks("beforeAll")[0].timeout(), "to be", 5000);
expect(suite.getHooks("beforeEach")[0].timeout(), "to be", 5000);
expect(suite.getHooks("afterAll")[0].timeout(), "to be", 5000);
expect(suite.getHooks("afterEach")[0].timeout(), "to be", 5000);
});
});
});

Expand Down
Loading