From 80bc99e28cb8f1da8b043e44c1705c5aacd9d3e9 Mon Sep 17 00:00:00 2001 From: Pavel Pustovalov Date: Wed, 1 Apr 2020 12:37:02 +0300 Subject: [PATCH] Sync docs with latest dom-testing-library --- docs/dom-testing-library/example-intro.md | 4 ++-- docs/example-react-router.md | 18 +++++++++++------- docs/pptr-testing-library/intro.md | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/dom-testing-library/example-intro.md b/docs/dom-testing-library/example-intro.md index 1ec820d90..923f27e6e 100644 --- a/docs/dom-testing-library/example-intro.md +++ b/docs/dom-testing-library/example-intro.md @@ -14,7 +14,7 @@ import { queryByTestId, // Tip: all queries are also exposed on an object // called "queries" which you could import here as well - wait, + waitFor, } from '@testing-library/dom' // adds special assertions like toHaveTextContent import '@testing-library/jest-dom/extend-expect' @@ -57,7 +57,7 @@ test('examples of some things', async () => { // Get elements by their text, just like a real user does. getByText(container, 'Print Username').click() - await wait(() => + await waitFor(() => expect(queryByTestId(container, 'printed-username')).toBeTruthy() ) diff --git a/docs/example-react-router.md b/docs/example-react-router.md index eedee0acf..efddacb7b 100644 --- a/docs/example-react-router.md +++ b/docs/example-react-router.md @@ -87,20 +87,23 @@ test('rendering a component that uses withRouter', () => { ## Reducing boilerplate -1. You can use the `wrapper` option to wrap a `MemoryRouter` around the component you want to render (`MemoryRouter` works when you don't need access to the history object itself in the test, but just need the components to be able to render and navigate). +1. You can use the `wrapper` option to wrap a `MemoryRouter` around the + component you want to render (`MemoryRouter` works when you don't need access + to the history object itself in the test, but just need the components to be + able to render and navigate). ```jsx import { MemoryRouter } from 'react-router-dom' test('full app rendering/navigating', () => { - const { container, getByText } = render(, {wrapper: MemoryRouter}) + const { container, getByText } = render(, { wrapper: MemoryRouter }) // verify page content for expected route expect(getByRole('heading')).toMatch('Home') }) ``` -2. If you find yourself adding Router components to your tests a lot, you may want to create -a helper function that wraps around `render`. +2. If you find yourself adding Router components to your tests a lot, you may + want to create a helper function that wraps around `render`. ```jsx // test utils file @@ -111,9 +114,11 @@ function renderWithRouter( history = createMemoryHistory({ initialEntries: [route] }), } = {} ) { - const Wrapper = ({children}) => {children} + const Wrapper = ({ children }) => ( + {children} + ) return { - ...render(ui, {wrapper: Wrapper}), + ...render(ui, { wrapper: Wrapper }), // adding `history` to the returned utilities to allow us // to reference it in our tests (just try to avoid using // this to test implementation details). @@ -137,4 +142,3 @@ test('rendering a component that uses withRouter', () => { expect(getByTestId('location-display')).toHaveTextContent(route) }) ``` - diff --git a/docs/pptr-testing-library/intro.md b/docs/pptr-testing-library/intro.md index b3956eedb..8c41ee63d 100644 --- a/docs/pptr-testing-library/intro.md +++ b/docs/pptr-testing-library/intro.md @@ -32,7 +32,7 @@ const $email = await getByLabelText($form, 'Email') // interact with puppeteer like usual await $email.type('pptr@example.com') // waiting works too! -await wait(() => getByText('Loading...')) +await waitFor(() => getByText('Loading...')) ``` A little too un-puppeteer for you? You can attach all the `DOM Testing Library`