Skip to content

Commit

Permalink
fix: test endAfterSubtests must not fail if test is done
Browse files Browse the repository at this point in the history
  • Loading branch information
lundibundi committed Mar 9, 2022
1 parent 631bb53 commit 4261d8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to

## [Unreleased][unreleased]

### Fixed

- bug where `test.endAfterSubtests()` would cause an error if the test was
finished before `endAfterSubtests` got a chance to process its checks.

## [0.8.1][] - 2022-03-06

### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/imperative-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ImperativeTest extends Test {
endAfterSubtests() {
this.waitingSubtests = true;
process.nextTick(() => {
if (!this._hasPendingSubtests()) this.end();
if (!this._hasPendingSubtests() && !this.done) this.end();
});
}

Expand Down
6 changes: 6 additions & 0 deletions test/imperative.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ metatests.test('nested test', t1 => {
});
});

metatests.test('nested test that ends before endAfterSubtests', t1 => {
t1.strictSame(123, 123);
t1.endAfterSubtests();
t1.end();
});

metatests.testAsync('nested test that ends after each subtest', test => {
let i = 0;
test.strictSame(++i, 1);
Expand Down

0 comments on commit 4261d8a

Please sign in to comment.