Skip to content

Commit

Permalink
test_runner: fix invalid timer call
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ErickWendel authored and ruyadorno committed Sep 28, 2023
1 parent 34c1741 commit b4d42a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/mock/mock_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class MockTimers {
ObjectDefineProperty(
nodeTimers,
'setTimeout',
this.#realSetTimeout,
this.#realTimersSetTimeout,
);
ObjectDefineProperty(
nodeTimers,
Expand Down
39 changes: 24 additions & 15 deletions test/parallel/test-runner-mock-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ describe('Mock Timers Test Suite', () => {
code: 'ERR_INVALID_ARG_VALUE',
});
});

it('should check that propertyDescriptor gets back after reseting timers', (t) => {
it('should check that propertyDescriptor gets back after resetting timers', (t) => {
const getDescriptor = (ctx, fn) => Object.getOwnPropertyDescriptor(ctx, fn);
const getCurrentTimersDescriptors = () => {
const timers = [
Expand All @@ -71,26 +70,36 @@ describe('Mock Timers Test Suite', () => {
nodeTimersPromises: nodeTimersPromisesDescriptors,
};
};
const before = getCurrentTimersDescriptors();

const originalDescriptors = getCurrentTimersDescriptors();

t.mock.timers.enable();
const during = getCurrentTimersDescriptors();
t.mock.timers.reset();
const after = getCurrentTimersDescriptors();

assert.deepStrictEqual(
before,
after,
);
for (const env in originalDescriptors) {
for (const prop in originalDescriptors[env]) {
const originalDescriptor = originalDescriptors[env][prop];
const afterDescriptor = after[env][prop];

assert.notDeepStrictEqual(
before,
during,
);
assert.deepStrictEqual(
originalDescriptor,
afterDescriptor,
);

assert.notDeepStrictEqual(
during,
after,
);
assert.notDeepStrictEqual(
originalDescriptor,
during[env][prop],
);

assert.notDeepStrictEqual(
during[env][prop],
after[env][prop],
);

}
}
});

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

0 comments on commit b4d42a8

Please sign in to comment.