Initial commit

This commit is contained in:
forceoranj
2021-10-16 01:53:56 +02:00
commit ebdd8dccdd
104 changed files with 29770 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
/**
* @jest-environment jsdom
*/
import { ReactNode } from "react"
import { render, screen } from "@testing-library/react"
import { MemoryRouter } from "react-router-dom"
import ErrorBoundary from "../index"
describe("<ErrorBoundary />", () => {
const tree = (children?: ReactNode) =>
render(
<MemoryRouter>
<ErrorBoundary>{children}</ErrorBoundary>
</MemoryRouter>
).container.firstChild
it("renders nothing if no children", () => {
expect(tree()).toMatchSnapshot()
})
it("renders children if no error", () => {
expect(
tree(
<div>
<h1>I am PeL</h1>
</div>
)
).toMatchSnapshot()
})
it("renders error view if an error occurs", () => {
console.error = jest.fn()
tree(<div>{new Error()}</div>)
expect(screen.getByTestId("error-view")).toBeInTheDocument()
})
})

View File

@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<ErrorBoundary /> renders children if no error 1`] = `
<div>
<h1>
I am PeL
</h1>
</div>
`;
exports[`<ErrorBoundary /> renders nothing if no children 1`] = `null`;