📜  类 2 的笑话模拟函数实例 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:35.105000             🧑  作者: Mango

代码示例1
import Person from "./Person";

beforeAll(() => {
    jest.spyOn(Person.prototype, 'sayMyName').mockImplementation(() => 'Hello');
});

afterAll(() => {
    jest.restoreAllMocks();
});

test('Modify class', () => {
    let person = new Person('Lorem', 'Ipsum');
    expect(person.sayMyName()).toBe("Hello");
    expect(person.bla()).toBe("bla");
});