-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prop types, error boundary tests
- Loading branch information
1 parent
95f4476
commit 9cca11b
Showing
6 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import App from "../App"; | ||
|
||
describe("App", () => { | ||
beforeEach(() => { | ||
render(<App />); | ||
}); | ||
|
||
it("renders Output heading", () => { | ||
expect(screen.getByText("Output").nodeName).toEqual("H2"); | ||
}); | ||
|
||
it("renders ErrorBoundary fallback element when draw function throws error", () => { | ||
jest.mock("../../../src/index", () => ({ | ||
draw: jest.fn(() => { | ||
throw new Error(); | ||
}), | ||
})); | ||
const input = screen.getByLabelText("Enter memory model JSON here"); | ||
// In order to get to draw function, input has to be valid json otherwise JSON.parse fails | ||
fireEvent.change(input, { target: { value: "[{}]" } }); | ||
const button = screen.getByTestId("input-submit-button"); | ||
fireEvent.click(button); | ||
|
||
const errorBoundary = screen.getByTestId("svg-display-error-boundary"); | ||
expect(errorBoundary.textContent).toEqual("Something went wrong"); | ||
}); | ||
|
||
it("calls console error when the input is not valid JSON", () => { | ||
const consoleErrorSpy = jest | ||
.spyOn(console, "error") | ||
.mockImplementation(); | ||
|
||
const input = screen.getByLabelText("Enter memory model JSON here"); | ||
fireEvent.change(input, { target: { value: "*&#*#(@(!(" } }); | ||
const button = screen.getByTestId("input-submit-button"); | ||
fireEvent.click(button); | ||
|
||
expect(consoleErrorSpy).toHaveBeenCalledWith( | ||
expect.stringMatching(/^Error parsing inputted JSON: /) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters