Skip to content

Commit b4d42a8

Browse files
ErickWendelruyadorno
authored andcommittedSep 28, 2023
test_runner: fix invalid timer call
Signed-off-by: Erick Wendel <[email protected]> PR-URL: #49477 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
1 parent 34c1741 commit b4d42a8

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed
 

‎lib/internal/test_runner/mock/mock_timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class MockTimers {
372372
ObjectDefineProperty(
373373
nodeTimers,
374374
'setTimeout',
375-
this.#realSetTimeout,
375+
this.#realTimersSetTimeout,
376376
);
377377
ObjectDefineProperty(
378378
nodeTimers,

‎test/parallel/test-runner-mock-timers.js

+24-15
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ describe('Mock Timers Test Suite', () => {
4646
code: 'ERR_INVALID_ARG_VALUE',
4747
});
4848
});
49-
50-
it('should check that propertyDescriptor gets back after reseting timers', (t) => {
49+
it('should check that propertyDescriptor gets back after resetting timers', (t) => {
5150
const getDescriptor = (ctx, fn) => Object.getOwnPropertyDescriptor(ctx, fn);
5251
const getCurrentTimersDescriptors = () => {
5352
const timers = [
@@ -71,26 +70,36 @@ describe('Mock Timers Test Suite', () => {
7170
nodeTimersPromises: nodeTimersPromisesDescriptors,
7271
};
7372
};
74-
const before = getCurrentTimersDescriptors();
73+
74+
const originalDescriptors = getCurrentTimersDescriptors();
75+
7576
t.mock.timers.enable();
7677
const during = getCurrentTimersDescriptors();
7778
t.mock.timers.reset();
7879
const after = getCurrentTimersDescriptors();
7980

80-
assert.deepStrictEqual(
81-
before,
82-
after,
83-
);
81+
for (const env in originalDescriptors) {
82+
for (const prop in originalDescriptors[env]) {
83+
const originalDescriptor = originalDescriptors[env][prop];
84+
const afterDescriptor = after[env][prop];
8485

85-
assert.notDeepStrictEqual(
86-
before,
87-
during,
88-
);
86+
assert.deepStrictEqual(
87+
originalDescriptor,
88+
afterDescriptor,
89+
);
8990

90-
assert.notDeepStrictEqual(
91-
during,
92-
after,
93-
);
91+
assert.notDeepStrictEqual(
92+
originalDescriptor,
93+
during[env][prop],
94+
);
95+
96+
assert.notDeepStrictEqual(
97+
during[env][prop],
98+
after[env][prop],
99+
);
100+
101+
}
102+
}
94103
});
95104

96105
it('should reset all timers when calling .reset function', (t) => {

0 commit comments

Comments
 (0)
Please sign in to comment.