How can the instance methods be mocked for a class that is being mocked with jest.mock?
For example, a class Logger is mocked:
import Person from "./Person";
import Logger from "./Logger";
jest.mock("./Logger");
describe("Person", () => {
it("calls Logger.method1() on instantiation", () => {
Logger.method1.mockImplementation(() => {}) // This fails as `method1` is an instance method but how can the instance method be mocked here?
new Person();
expect(Logger.method1).toHaveBeenCalled();
});
});
Run Code Online (Sandbox Code Playgroud) 假设我有两个 Numpy 数组 A 和 B,我想看看是否有sorted(A) == sorted(B)?例如:如果A = [5,3,2,4]和B = [3,2,5,4],那么我必须得到真。这样做的最快方法是什么?