Skip to content

Instantly share code, notes, and snippets.

@Walkeryr
Created May 31, 2022 21:38
Show Gist options
  • Save Walkeryr/fcbc05579853eeda15f9663feafdcf69 to your computer and use it in GitHub Desktop.
Save Walkeryr/fcbc05579853eeda15f9663feafdcf69 to your computer and use it in GitHub Desktop.
Jest testing snippets

Mocking console.error

Requires jsdom

describe("module", () => {
  beforeAll(() => {
    jest.spyOn(console, "error").mockImplementation(() => {});
  });

  it("should read valid data from localStorage", () => {
    expect(console.error).toBeCalledWith(
      expect.stringContaining("Unable to parse data from serialised JSON")
    );
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment