Last active
January 17, 2020 22:20
-
-
Save MrLeebo/166da7c465ea286d8ba316676bd0c1f2 to your computer and use it in GitHub Desktop.
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
import { prefetchQuery } from "react-query"; | |
describe('MyComponent', () => { | |
beforeEach(() => { | |
// using react-query for data fetching makes it easy to mock out your API calls | |
return prefetchQuery(["myQuery"], () => [{ name: 'Steve', role: 'Developer' }]) | |
}) | |
it('should open a dialog', async () => { | |
// visit the page | |
const page = visit('/mycomponent/steve') | |
// interact with a button | |
const button = await page.findByText("Open Dialog") | |
fireEvent.click(button) | |
// test your expectations | |
const dialog = await page.findByRole("dialog") | |
expect(dialog).toHaveTextContent("Hello, Steve the Developer!") | |
}) | |
}) |
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
import React from "react"; | |
import { render } from "@testing-library/react"; | |
import { clearQueryCache } from "react-query"; | |
import "@testing-library/jest-dom/extend-expect"; | |
import { AppContext } from "../../src/contexts"; | |
const defaultOptions = {} | |
global.visit = (path, options = defaultOptions) => { | |
return render( | |
<AppContext.Provider value={options}> | |
<React.Suspense fallback={"Loading..."}> | |
<ErrorBoundary> | |
<MemoryRouter initialEntries={[path]}> | |
<App /> | |
</MemoryRouter> | |
</ErrorBoundary> | |
</React.Suspense> | |
</AppContext.Provider> | |
); | |
}; | |
afterEach(clearQueryCache); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment