'How to mock instance methods of a class mocked with jest.mock?
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();
});
});
Solution 1:[1]
You can check with Azure Monitor OpenTelemetry based to configure your own logs for Java Applications.
Can be achieved with below steps:
Set application insights connection as environmental variable as below:
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...Check connection string for AI resource.
Configure settings in applicationinsights,json settings.
Also can set user id with adding open telemetry api and setting user_id in your code.
For more detail information, refer to MS Docs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SaiKarri-MT |
