Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: fix mock.method to support class instances #45608

Merged
merged 19 commits into from Dec 17, 2022
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 16 additions & 6 deletions test/parallel/test-runner-mocking.js
Expand Up @@ -446,17 +446,27 @@ test('spy functions don\'t affect the prototype chain', (t) => {

const msg = 'ok';

const ABeforeMockIsUnchanged = Object.getOwnPropertyDescriptor(A, A.someTask.name);
const BBeforeMockIsUnchanged = Object.getOwnPropertyDescriptor(B, B.someTask.name);
const CBeforeMockShouldNotHaveDesc = Object.getOwnPropertyDescriptor(C, C.someTask.name);
ErickWendel marked this conversation as resolved.
Show resolved Hide resolved

t.mock.method(C, C.someTask.name);
C.someTask(msg);
const BAfterMockIsUnchanged = Object.getOwnPropertyDescriptor(B, B.someTask.name);

const AAfterMockIsUnchanged = Object.getOwnPropertyDescriptor(A, A.someTask.name);
const CAfterMockHasDescriptor = Object.getOwnPropertyDescriptor(C, C.someTask.name);

assert.strictEqual(CBeforeMockShouldNotHaveDesc, undefined);
assert.ok(CAfterMockHasDescriptor);

assert.strictEqual(B.someTask.mock, undefined);
assert.strictEqual(A.someTask.mock, undefined);
assert.deepStrictEqual(ABeforeMockIsUnchanged, AAfterMockIsUnchanged);
assert.strictEqual(BBeforeMockIsUnchanged, BAfterMockIsUnchanged);
assert.strictEqual(BBeforeMockIsUnchanged, undefined);

assert.strictEqual(C.someTask.mock.restore(), undefined);
C.someTask(msg);
assert.strictEqual(C.someTask.mock, undefined);
assert.strictEqual(B.someTask.mock, undefined);
assert.strictEqual(A.someTask.mock, undefined);
const CAfterRestoreKeepsDescriptor = Object.getOwnPropertyDescriptor(C, C.someTask.name);
assert.ok(CAfterRestoreKeepsDescriptor);
});

test('mocked functions report thrown errors', (t) => {
Expand Down