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

📅  最后修改于: 2022-03-11 14:56:32.954000             🧑  作者: Mango

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

test('Modify only instance', () => {
    let person = new Person('Lorem', 'Ipsum');
    let spy = jest.spyOn(person, 'sayMyName').mockImplementation(() => 'Hello');

    expect(person.sayMyName()).toBe("Hello");
    expect(person.bla()).toBe("bla");

    // unnecessary in this case, putting it here just to illustrate how to "unmock" a method
    spy.mockRestore();
});