test_runner: fix invalid timer call

Signed-off-by: Erick Wendel <erick.workspace@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/49477
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
Erick Wendel 2023-09-05 18:17:28 -03:00 committed by GitHub
parent 21759bdfed
commit a61bc9d933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 16 deletions

View File

@ -372,7 +372,7 @@ class MockTimers {
ObjectDefineProperty(
nodeTimers,
'setTimeout',
this.#realSetTimeout,
this.#realTimersSetTimeout,
);
ObjectDefineProperty(
nodeTimers,

View File

@ -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 = [
@ -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) => {