Skip to content

Instantly share code, notes, and snippets.

@jogilvyt
Created January 19, 2021 17:09
Show Gist options
  • Save jogilvyt/2d9773059b469e57a53661462cff5b7a to your computer and use it in GitHub Desktop.
Save jogilvyt/2d9773059b469e57a53661462cff5b7a to your computer and use it in GitHub Desktop.
End to end test for counter component
it("should initialise with the value stored in localStorage", () => {
// set the localStorage to a value other than 0
localStorage.setItem("count", 15);
// render the App and check it initialises to the value in localStorage
render(<App />);
screen.getByText(/Number: 15/);
// click the increment button and check the localStorage is updated
const incrementButton = screen.getByText(/\+1/);
fireEvent.click(incrementButton);
screen.getByText(/Number: 16/);
expect(localStorage.getItem("count")).toBe("16");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment