Skip to content

Commit 12dcd5f

Browse files
committed
This probably fixes the random overrides
1 parent 519ed18 commit 12dcd5f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

exercises/concept/captains-log/captains-log.spec.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, test } from '@jest/globals';
1+
import { describe, expect, test, beforeEach, afterEach } from '@jest/globals';
22
import {
33
randomShipRegistryNumber,
44
randomStardate,
@@ -33,24 +33,33 @@ function loadDie(...values) {
3333
}
3434

3535
describe('randomStardate', () => {
36-
test('stardate is between 41000 and 42000', () => {
36+
let restore;
37+
38+
beforeEach(() => {
3739
const min = 0;
3840
const max = 1 - Number.EPSILON * 32;
3941

4042
// prettier-ignore
41-
const restore = loadDie(
43+
restore = loadDie(
4244
min, min, min, min, min, min,
4345
max, max, max, max, max, max,
4446
0.5, 0.5, 0.5, 0.5, 0.5, 0.5
4547
);
48+
});
49+
50+
afterEach(() => {
51+
if (restore) {
52+
restore();
53+
restore = undefined;
54+
}
55+
});
4656

57+
test('stardate is between 41000 and 42000', () => {
4758
for (let i = 0; i < 10_000; i++) {
4859
const starDate = randomStardate();
4960
expect(starDate).toBeGreaterThanOrEqual(41_000);
5061
expect(starDate).toBeLessThan(42_000);
5162
}
52-
53-
restore();
5463
});
5564
});
5665

0 commit comments

Comments
 (0)