diff --git a/docs/dom-testing-library/api-async.mdx b/docs/dom-testing-library/api-async.mdx index fdae4568f..71be357a1 100644 --- a/docs/dom-testing-library/api-async.mdx +++ b/docs/dom-testing-library/api-async.mdx @@ -106,14 +106,14 @@ el.parentElement.removeChild(el) or an empty array: ```javascript -waitForElementToBeRemoved(null).catch(err => console.log(err)) -waitForElementToBeRemoved(queryByText(/not here/i)).catch(err => +waitForElementToBeRemoved(null).catch((err) => console.log(err)) +waitForElementToBeRemoved(queryByText(/not here/i)).catch((err) => console.log(err) ) -waitForElementToBeRemoved(queryAllByText(/not here/i)).catch(err => +waitForElementToBeRemoved(queryAllByText(/not here/i)).catch((err) => console.log(err) ) -waitForElementToBeRemoved(() => getByText(/not here/i)).catch(err => +waitForElementToBeRemoved(() => getByText(/not here/i)).catch((err) => console.log(err) ) @@ -165,7 +165,7 @@ changed: const container = document.createElement('div') waitForDomChange({ container }) .then(() => console.log('DOM changed!')) - .catch(err => console.log(`Error you need to deal with: ${err}`)) + .catch((err) => console.log(`Error you need to deal with: ${err}`)) container.append(document.createElement('p')) // if šŸ‘† was the only code affecting the container and it was not run, // waitForDomChange would throw an error @@ -179,7 +179,7 @@ container ```javascript const container = document.createElement('div') container.setAttribute('data-cool', 'true') -waitForDomChange({ container }).then(mutationsList => { +waitForDomChange({ container }).then((mutationsList) => { const mutation = mutationsList[0] console.log( `was cool: ${mutation.oldValue}\ncurrently cool: ${mutation.target.dataset.cool}` diff --git a/docs/dom-testing-library/api-configuration.mdx b/docs/dom-testing-library/api-configuration.mdx index f26a83c98..fb84d2698 100644 --- a/docs/dom-testing-library/api-configuration.mdx +++ b/docs/dom-testing-library/api-configuration.mdx @@ -3,8 +3,8 @@ id: api-configuration title: Configuration --- -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; +import Tabs from '@theme/Tabs' +import TabItem from '@theme/TabItem' ## Configuration @@ -50,12 +50,13 @@ option. screen.getByTestId('foo', { suggest: false }) // will not throw a suggestion ``` -`testIdAttribute`: The attribute used by [`getByTestId`](api-queries.mdx#bytestid) -and related queries. Defaults to `data-testid`. +`testIdAttribute`: The attribute used by +[`getByTestId`](api-queries.mdx#bytestid) and related queries. Defaults to +`data-testid`. `getElementError`: A function that returns the error used when -[`getBy*`](api-queries.mdx#getby) or [`getAllBy*`](api-queries.mdx#getallby) fail. Takes -the error message and container object as arguments. +[`getBy*`](api-queries.mdx#getby) or [`getAllBy*`](api-queries.mdx#getallby) +fail. Takes the error message and container object as arguments. `asyncUtilTimeout`: The global timeout value in milliseconds used by `waitFor` utilities. Defaults to 1000ms. diff --git a/docs/dom-testing-library/api-events.mdx b/docs/dom-testing-library/api-events.mdx index 3cba83169..ffcc3cce3 100644 --- a/docs/dom-testing-library/api-events.mdx +++ b/docs/dom-testing-library/api-events.mdx @@ -3,8 +3,8 @@ id: api-events title: Firing Events --- -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; +import Tabs from '@theme/Tabs' +import TabItem from '@theme/TabItem' > Most projects have a few use cases for `fireEvent`, but the majority of the > time you should probably use @@ -149,20 +149,20 @@ bound callback. }> - ```jsx - import { render, screen, fireEvent } from '@testing-library/react' +```jsx +import { render, screen, fireEvent } from '@testing-library/react' - const Button = ({ onClick, children }) => ( - - ) +const Button = ({ onClick, children }) => ( + +) - test('calls onClick prop when clicked', () => { - const handleClick = jest.fn() - render() - fireEvent.click(screen.getByText(/click me/i)) - expect(handleClick).toHaveBeenCalledTimes(1) - }) - ``` +test('calls onClick prop when clicked', () => { + const handleClick = jest.fn() + render() + fireEvent.click(screen.getByText(/click me/i)) + expect(handleClick).toHaveBeenCalledTimes(1) +}) +``` diff --git a/docs/dom-testing-library/api-helpers.mdx b/docs/dom-testing-library/api-helpers.mdx index 258fcec6e..c749d1c3e 100644 --- a/docs/dom-testing-library/api-helpers.mdx +++ b/docs/dom-testing-library/api-helpers.mdx @@ -3,8 +3,8 @@ id: api-helpers title: Helpers --- -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; +import Tabs from '@theme/Tabs' +import TabItem from '@theme/TabItem' ## Custom Queries @@ -68,8 +68,7 @@ module.exports = { The `buildQueries` helper allows you to create custom queries with all standard [variants](api-queries.mdx) of queries in testing-library. -See the -[Add custom queries](react-testing-library/setup.mdx#add-custom-queries) +See the [Add custom queries](react-testing-library/setup.mdx#add-custom-queries) section of the custom render guide for example usage. ### Using other assertion libraries @@ -138,32 +137,32 @@ could do: }> - ```js - import { within } from '@testing-library/dom' +```js +import { within } from '@testing-library/dom' - const { getByText } = within(document.getElementById('messages')) - const helloMessage = getByText('hello') - ``` +const { getByText } = within(document.getElementById('messages')) +const helloMessage = getByText('hello') +``` - ```jsx - import { render, within } from '@testing-library/react' +```jsx +import { render, within } from '@testing-library/react' - const { getByLabelText } = render() - const signinModal = getByLabelText('Sign In') - within(signinModal).getByPlaceholderText('Username') - ``` +const { getByLabelText } = render() +const signinModal = getByLabelText('Sign In') +within(signinModal).getByPlaceholderText('Username') +``` - ```js - cy.get('form').within(() => { - cy.findByText('Button Text').should('be.disabled') - }) - ``` +```js +cy.get('form').within(() => { + cy.findByText('Button Text').should('be.disabled') +}) +``` diff --git a/docs/dom-testing-library/api-queries.mdx b/docs/dom-testing-library/api-queries.mdx index bd5da1eef..bc782dd22 100644 --- a/docs/dom-testing-library/api-queries.mdx +++ b/docs/dom-testing-library/api-queries.mdx @@ -3,8 +3,8 @@ id: api-queries title: Queries --- -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; +import Tabs from '@theme/Tabs' +import TabItem from '@theme/TabItem' ## Variants @@ -1006,7 +1006,7 @@ To override normalization to remove some Unicode characters whilst keeping some ```javascript screen.getByText('text', { - normalizer: str => + normalizer: (str) => getDefaultNormalizer({ trim: false })(str).replace(/[\u200E-\u200F]*/g, ''), }) ``` diff --git a/docs/dom-testing-library/cheatsheet.mdx b/docs/dom-testing-library/cheatsheet.mdx index 9fb7c8efa..42b376b8d 100644 --- a/docs/dom-testing-library/cheatsheet.mdx +++ b/docs/dom-testing-library/cheatsheet.mdx @@ -77,25 +77,29 @@ See [Which query should I use?](guide-which-query.mdx) ## Async -See [Async API](dom-testing-library/api-async.mdx). Remember to `await` or `.then()` -the result of async functions in your tests! +See [Async API](dom-testing-library/api-async.mdx). Remember to `await` or +`.then()` the result of async functions in your tests! -- **waitFor** (Promise) retry the function within until it stops throwing or times - out +- **waitFor** (Promise) retry the function within until it stops throwing or + times out - **waitForElementToBeRemoved** (Promise) retry the function until it no longer returns a DOM node > **Deprecated since v7.0.0:** -> - **wait** (Promise) retry the function within until it stops throwing or times -> - **waitForElement** (Promise) retry the function until it returns an element or -> an array of elements -> - `findBy` and `findAllBy` queries are async and retry until either a timeout -> or if the query returns successfully; they wrap `waitForElement` -> - **waitForDomChange** (Promise) retry the function each time the DOM is changed +> +> - **wait** (Promise) retry the function within until it stops throwing or +> times +> - **waitForElement** (Promise) retry the function until it returns an element +> or an array of elements +> - `findBy` and `findAllBy` queries are async and retry until either a timeout +> or if the query returns successfully; they wrap `waitForElement` +> - **waitForDomChange** (Promise) retry the function each time the DOM is +> changed ## Events -See [Considerations for fireEvent](guide-events.mdx), [Events API](api-events.mdx) +See [Considerations for fireEvent](guide-events.mdx), +[Events API](api-events.mdx) - **fireEvent** trigger DOM event: `fireEvent(node, event)` - **fireEvent.\*** helpers for default event types diff --git a/docs/dom-testing-library/faq.mdx b/docs/dom-testing-library/faq.mdx index 923f89a83..e85b78667 100644 --- a/docs/dom-testing-library/faq.mdx +++ b/docs/dom-testing-library/faq.mdx @@ -27,7 +27,9 @@ As you write your tests, keep in mind:
-What if my app is localized and I don't have access to the text in test? + + What if my app is localized and I don't have access to the text in test? + This is fairly common. Our first bit of advice is to try to get the default text used in your tests. That will make everything much easier (more than just using @@ -38,7 +40,10 @@ with `data-testid`s (which is not bad anyway).
-I really don't like data-testids, but none of the other queries make sense. Do I have to use a data-testid? + + I really don't like data-testids, but none of the other queries make sense. Do + I have to use a data-testid? + Definitely not. That said, a common reason people don't like the `data-testid` attribute is they're concerned about shipping that to production. I'd suggest @@ -67,7 +72,10 @@ const rootElement = container.firstChild
-What if I’m iterating over a list of items that I want to put the data-testid="item" attribute on. How do I distinguish them from each other? + + What if I’m iterating over a list of items that I want to put the + data-testid="item" attribute on. How do I distinguish them from each other? + You can make your selector just choose the one you want by including :nth-child in the selector. @@ -109,7 +117,6 @@ library for more info. - [guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106 diff --git a/docs/example-codesandbox.mdx b/docs/example-codesandbox.mdx index 7d54c6442..9fca1aef9 100644 --- a/docs/example-codesandbox.mdx +++ b/docs/example-codesandbox.mdx @@ -8,7 +8,17 @@ You can find runnable examples for many common use cases on Codesandbox. [![Open react-testing-library-examples](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/kentcdodds/react-testing-library-examples/tree/master/) - + ## Playground diff --git a/docs/example-drag.mdx b/docs/example-drag.mdx index 2024ebfe7..2d0fcecff 100644 --- a/docs/example-drag.mdx +++ b/docs/example-drag.mdx @@ -57,11 +57,11 @@ function getElementClientCenter(element) { } } -const getCoords = charlie => +const getCoords = (charlie) => isElement(charlie) ? getElementClientCenter(charlie) : charlie -const sleep = ms => - new Promise(resolve => { +const sleep = (ms) => + new Promise((resolve) => { setTimeout(resolve, ms) }) diff --git a/docs/example-external.mdx b/docs/example-external.mdx index c85b88aaa..a5f54a59e 100644 --- a/docs/example-external.mdx +++ b/docs/example-external.mdx @@ -20,5 +20,10 @@ sidebar_label: External Examples Tolinski - what is react testing library + what is react testing library diff --git a/docs/example-input-event.mdx b/docs/example-input-event.mdx index 29f6663c3..689439bda 100644 --- a/docs/example-input-event.mdx +++ b/docs/example-input-event.mdx @@ -11,16 +11,16 @@ sidebar_label: Input Event > [`user-event`](ecosystem-user-event.mdx) ```jsx -import React, {useState} from 'react' +import React, { useState } from 'react' import { render, fireEvent } from '@testing-library/react' function CostInput() { const [value, setValue] = useState('') - removeDollarSign = value => (value[0] === '$' ? value.slice(1) : value) - getReturnValue = value => (value === '' ? '' : `$${value}`) - - handleChange = ev => { + removeDollarSign = (value) => (value[0] === '$' ? value.slice(1) : value) + getReturnValue = (value) => (value === '' ? '' : `$${value}`) + + handleChange = (ev) => { ev.preventDefault() const inputtedValue = ev.currentTarget.value const noDollarSign = removeDollarSign(inputtedValue) @@ -28,13 +28,7 @@ function CostInput() { setValue(getReturnValue(noDollarSign)) } - return ( - - ) + return } const setup = () => { diff --git a/docs/example-react-context.mdx b/docs/example-react-context.mdx index bc457a12c..2864f3261 100644 --- a/docs/example-react-context.mdx +++ b/docs/example-react-context.mdx @@ -53,7 +53,7 @@ test('NameProvider composes full name from first, last', () => { } customRender( - {value => Received: {value}} + {(value) => Received: {value}} , { providerProps } ) diff --git a/docs/example-react-modal.mdx b/docs/example-react-modal.mdx index a494f2dec..b2125fe1a 100644 --- a/docs/example-react-modal.mdx +++ b/docs/example-react-modal.mdx @@ -23,7 +23,7 @@ const Modal = ({ onClose, children }) => { return ReactDOM.createPortal(
-
e.stopPropagation()}> +
e.stopPropagation()}> {children}
diff --git a/docs/example-react-transition-group.mdx b/docs/example-react-transition-group.mdx index b9424265f..763638125 100644 --- a/docs/example-react-transition-group.mdx +++ b/docs/example-react-transition-group.mdx @@ -20,7 +20,7 @@ function Fade({ children, ...props }) { function HiddenMessage({ initialShow }) { const [show, setShow] = useState(initialShow || false) - const toggle = () => setShow(prevState => !prevState) + const toggle = () => setShow((prevState) => !prevState) return (
@@ -33,7 +33,7 @@ function HiddenMessage({ initialShow }) { jest.mock('react-transition-group', () => { const FakeTransition = jest.fn(({ children }) => children) - const FakeCSSTransition = jest.fn(props => + const FakeCSSTransition = jest.fn((props) => props.in ? {props.children} : null ) return { CSSTransition: FakeCSSTransition, Transition: FakeTransition } @@ -70,7 +70,7 @@ function Fade({ children, ...props }) { function HiddenMessage({ initialShow }) { const [show, setShow] = useState(initialShow || false) - const toggle = () => setShow(prevState => !prevState) + const toggle = () => setShow((prevState) => !prevState) return (
diff --git a/docs/preact-testing-library/api.mdx b/docs/preact-testing-library/api.mdx index a9ed5da28..c8ac61d0d 100644 --- a/docs/preact-testing-library/api.mdx +++ b/docs/preact-testing-library/api.mdx @@ -16,8 +16,8 @@ sidebar_label: API This library re-exports everything from the DOM Testing Library (`@testing-library/dom`). See the -[documentation](dom-testing-library/api-queries.mdx) to see what goodies you -can use. +[documentation](dom-testing-library/api-queries.mdx) to see what goodies you can +use. ## `render` @@ -33,20 +33,20 @@ const { results } = render(, { options }) | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | | `container` | The HTML element the component is mounted to. | baseElement | | `baseElement` | The root HTML element to which the container is appended to. | document.body | -| `queries` | Queries to bind to the baseElement. See [getQueriesForElement](dom-testing-library/api-helpers.mdx#within-and-getqueriesforelement-apis). | null | +| `queries` | Queries to bind to the baseElement. See [getQueriesForElement](dom-testing-library/api-helpers.mdx#within-and-getqueriesforelement-apis). | null | | `hydrate` | Used when the component has already been mounted and requires a rerender. Not needed for most people. The rerender function passed back to you does this already. | false | | `wrapper` | A parent component to wrap YourComponent. | null | ### Results -| Result | Description | -| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `container` | The HTML element the component is mounted to. | -| `baseElement` | The root HTML element to which the container is appended to. | +| Result | Description | +| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `container` | The HTML element the component is mounted to. | +| `baseElement` | The root HTML element to which the container is appended to. | | `debug` | Logs the baseElement using [prettyDom](dom-testing-library/api-helpers.mdx#prettydom). | -| `unmount` | Unmounts the component from the container. | -| `rerender` | Calls render again passing in the original arguments and sets hydrate to true. | -| `asFragment` | Returns the innerHTML of the container. | +| `unmount` | Unmounts the component from the container. | +| `rerender` | Calls render again passing in the original arguments and sets hydrate to true. | +| `asFragment` | Returns the innerHTML of the container. | | `...queries` | Returns all [query functions](dom-testing-library/api-queries.mdx) to be used on the baseElement. If you pass in `query` arguments than this will be those, otherwise all. | ## `cleanup` diff --git a/docs/preact-testing-library/example.mdx b/docs/preact-testing-library/example.mdx index 78d4b79b9..331b0128d 100644 --- a/docs/preact-testing-library/example.mdx +++ b/docs/preact-testing-library/example.mdx @@ -19,7 +19,7 @@ function HiddenMessage({ children }) { setShowMessage(e.target.checked)} + onChange={(e) => setShowMessage(e.target.checked)} checked={showMessage} /> {showMessage ? children : null} diff --git a/docs/react-testing-library/api.mdx b/docs/react-testing-library/api.mdx index ed5bafa39..1806b5cea 100644 --- a/docs/react-testing-library/api.mdx +++ b/docs/react-testing-library/api.mdx @@ -249,7 +249,7 @@ const TestComponent = () => { const [count, setCounter] = useState(0) return ( - ) diff --git a/docs/react-testing-library/example-intro.mdx b/docs/react-testing-library/example-intro.mdx index 6cef2d94b..c0afe6e48 100644 --- a/docs/react-testing-library/example-intro.mdx +++ b/docs/react-testing-library/example-intro.mdx @@ -208,13 +208,13 @@ export default function Fetch({ url }) { const fetchGreeting = async () => { axios .get(url) - .then(response => { + .then((response) => { const { data } = response const { greeting } = data dispatch({ type: 'SUCCESS', greeting }) setButtonClicked(true) }) - .catch(error => { + .catch((error) => { dispatch({ type: 'ERROR', error }) }) } diff --git a/docs/react-testing-library/faq.mdx b/docs/react-testing-library/faq.mdx index b4abf1b1a..b93ef6a56 100644 --- a/docs/react-testing-library/faq.mdx +++ b/docs/react-testing-library/faq.mdx @@ -100,7 +100,9 @@ As you write your tests, keep in mind:
-If I can't use shallow rendering, how do I mock out components in tests? + + If I can't use shallow rendering, how do I mock out components in tests? + In general, you should avoid mocking out components (see [the Guiding Principles section](guiding-principles.mdx)). However if you need @@ -112,7 +114,7 @@ libraries. I don't want my tests to wait for animations to end. ```javascript jest.mock('react-transition-group', () => { const FakeTransition = jest.fn(({ children }) => children) - const FakeCSSTransition = jest.fn(props => + const FakeCSSTransition = jest.fn((props) => props.in ? {props.children} : null ) return { CSSTransition: FakeCSSTransition, Transition: FakeTransition } @@ -151,8 +153,10 @@ Learn more about how Jest mocks work from my blog post:
-What about enzyme is "bloated with complexity and features" and "encourage -poor testing practices"? + + What about enzyme is "bloated with complexity and features" and "encourage + poor testing practices"? + Most of the damaging features have to do with encouraging testing implementation details. Primarily, these are diff --git a/docs/react-testing-library/intro.mdx b/docs/react-testing-library/intro.mdx index 1bd14ec83..da81e0781 100644 --- a/docs/react-testing-library/intro.mdx +++ b/docs/react-testing-library/intro.mdx @@ -74,7 +74,12 @@ Have a look at the "What is React Testing library?" video below for an introduction to the library. - what is react testing library + what is react testing library Also, don't miss this diff --git a/docs/react-testing-library/migrate-from-enzyme.mdx b/docs/react-testing-library/migrate-from-enzyme.mdx index 8476570d1..81ae0d175 100644 --- a/docs/react-testing-library/migrate-from-enzyme.mdx +++ b/docs/react-testing-library/migrate-from-enzyme.mdx @@ -63,9 +63,8 @@ work can be done collaboratively and spread over some time. ## Install React Testing Library -You can check -[this page](setup.mdx) for -the complete installation and setup guide. +You can check [this page](setup.mdx) for the complete installation and setup +guide. Here is what you should do, first you need to install the React Testing Library: @@ -126,13 +125,13 @@ different name, and the template updates accordingly. Check the live version on [Codesandbox](https://codesandbox.io/s/ecstatic-hellman-fh7in) ```jsx -const Welcome = props => { +const Welcome = (props) => { const [values, setValues] = useState({ firstName: props.firstName, lastName: props.lastName, }) - const handleChange = event => { + const handleChange = (event) => { setValues({ ...values, [event.target.name]: event.target.value }) } @@ -200,8 +199,7 @@ automatically cleans up the output for each test, so you don't need to call The other thing that you might notice is `getByRole` which has `heading` as its value. `heading` is the accessible role of the `h1` element. You can learn more -about them on -[queries](dom-testing-library/api-queries.mdx#byrole) +about them on [queries](dom-testing-library/api-queries.mdx#byrole) documentation page. One of the things people quickly learn to love about Testing Library is how it encourages you to write more accessible applications (because if it's not accessible, then it's harder to test). @@ -245,8 +243,8 @@ like `
` do not have one. You could use different approaches to access the `
` element, but we recommend trying to access elements by their implicit `role` to make sure your component is accessible by people with disabilities and those who are using screen readers. This -[section](dom-testing-library/api-queries.mdx#byrole) -of the query page might help you to understand better. +[section](dom-testing-library/api-queries.mdx#byrole) of the query page might +help you to understand better. > Keep in mind that a `
` must have a `name` attribute in order to have an > implicit `role` of `form` (as required by the specification). @@ -260,13 +258,11 @@ it's not recommended for the reasons stated in this paragraph). We made some handy query APIs which help you to access the component elements very efficiently, and you can see the -[list of available queries](dom-testing-library/api-queries.mdx) -in detail. +[list of available queries](dom-testing-library/api-queries.mdx) in detail. Something else that people have a problem with is that they're not sure which query should they use, luckily we have a great page which explains -[which query to use](guide-which-query.mdx), so -don't forget to check it out! +[which query to use](guide-which-query.mdx), so don't forget to check it out! If you still have a problem with the React Testing Library's queries, and you're not sure which query to use, then check out @@ -294,13 +290,11 @@ to handle fewer things! There are two ways to simulate user events, one is a perfect library named [`user-event`](https://github.com/testing-library/user-event), and the other way -is to use -[`fireEvent`](dom-testing-library/api-events.mdx). -`user-event` is actually built on top of `fireEvent` which simply calls -`dispatchEvent` on the element given. However, `user-event` is generally -recommended because it ensures that all the events are fired in the correct -order for typical user interactions which helps to ensure your tests resemble -the way your software is used. +is to use [`fireEvent`](dom-testing-library/api-events.mdx). `user-event` is +actually built on top of `fireEvent` which simply calls `dispatchEvent` on the +element given. However, `user-event` is generally recommended because it ensures +that all the events are fired in the correct order for typical user interactions +which helps to ensure your tests resemble the way your software is used. To use the `@testing-library/user-event` module, you first need to install it: diff --git a/docs/svelte-testing-library/api.mdx b/docs/svelte-testing-library/api.mdx index 204a8a86d..4788921c5 100644 --- a/docs/svelte-testing-library/api.mdx +++ b/docs/svelte-testing-library/api.mdx @@ -16,8 +16,8 @@ sidebar_label: API This library re-exports everything from the DOM Testing Library (`@testing-library/dom`). See the -[documentation](dom-testing-library/api-queries.mdx) to see what goodies you -can use. +[documentation](dom-testing-library/api-queries.mdx) to see what goodies you can +use. šŸ“ `fireEvent` is an `async` method when imported from `@testing-library/svelte`. This is because it calls [`tick`][svelte-tick] which @@ -57,9 +57,9 @@ const { results } = render(YourComponent, { myProp: 'value' }) ### Render Options -| Option | Description | Default | -| ----------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------- | -| `container` | The HTML element the component is mounted into. | `document.body` | +| Option | Description | Default | +| ----------- | --------------------------------------------------------------------------------------------------------------------------------------- | --------------- | +| `container` | The HTML element the component is mounted into. | `document.body` | | `queries` | Queries to bind to the container. See [getQueriesForElement](dom-testing-library/api-helpers.mdx#within-and-getqueriesforelement-apis). | `null` | ### Results @@ -68,10 +68,10 @@ const { results } = render(YourComponent, { myProp: 'value' }) | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `container` | The HTML element the component is mounted into. | | `component` | The newly created Svelte component. Generally, this should only be used when testing exported functions, or when you're testing developer facing API's. Outside of said cases avoid using the component directly to build tests, instead of interacting with the rendered Svelte component, work with the DOM. Have a read of [Avoid the Test User](https://kentcdodds.com/blog/avoid-the-test-user) by Kent C. Dodds to understand the difference between the **end user** and **developer user**. | -| `debug` | Logs the `container` using [prettyDom](dom-testing-library/api-helpers.mdx#prettydom). | +| `debug` | Logs the `container` using [prettyDom](dom-testing-library/api-helpers.mdx#prettydom). | | `unmount` | Unmounts the component from the `target` by calling `component.$destroy()`. | | `rerender` | Calls render again destroying the old component, and mounting the new component on the original `target` with any new options passed in. | -| `...queries` | Returns all [query functions](dom-testing-library/api-queries.mdx) that are bound to the `container`. If you pass in `query` arguments than this will be those, otherwise all. | +| `...queries` | Returns all [query functions](dom-testing-library/api-queries.mdx) that are bound to the `container`. If you pass in `query` arguments than this will be those, otherwise all. | ## `cleanup` diff --git a/docs/testcafe-testing-library/intro.mdx b/docs/testcafe-testing-library/intro.mdx index 848e1adf9..144d1059e 100644 --- a/docs/testcafe-testing-library/intro.mdx +++ b/docs/testcafe-testing-library/intro.mdx @@ -10,8 +10,7 @@ within [Testcafe](https://devexpress.github.io/testcafe/) for cross-browser end-to-end web testing. If you are new to the testing-library approach for writing tests, check out the -[this guide on which query to use](guide-which-query.mdx) -as well as the +[this guide on which query to use](guide-which-query.mdx) as well as the [cheat sheet](dom-testing-library/cheatsheet.mdx). ## Install @@ -57,24 +56,24 @@ To show some simple examples (from ```javascript import { screen } from '@testing-library/testcafe' -test('getByPlaceHolderText', async t => { +test('getByPlaceHolderText', async (t) => { await t.typeText( screen.getByPlaceholderText('Placeholder Text'), 'Hello Placeholder' ) }) -test('getByText', async t => { +test('getByText', async (t) => { await t.click(screen.getByText('getByText')) }) -test('getByLabelText', async t => { +test('getByLabelText', async (t) => { await t.typeText( screen.getByLabelText('Label For Input Labelled By Id'), 'Hello Input Labelled By Id' ) }) -test('queryAllByText', async t => { +test('queryAllByText', async (t) => { await t.expect(screen.queryAllByText('Button Text').exists).ok() await t .expect(screen.queryAllByText('Non-existing Button Text').exists) @@ -92,7 +91,7 @@ Testing Library][config] in a few different ways: ```javascript import { configureOnce, getByTestId } from '@testing-library/testcafe' -test('can be configured once in a single page load', async t => { +test('can be configured once in a single page load', async (t) => { await configureOnce({ testIdAttribute: 'data-other-test-id' }) await t.click(screen.getByTestId('other-id')) }) @@ -107,11 +106,11 @@ fixture`configure`.clientScripts( configure({ testIdAttribute: 'data-automation-id' }) ).page`http://localhost:13370` -test('supports alternative testIdAttribute', async t => { +test('supports alternative testIdAttribute', async (t) => { await t.click(screen.getByTestId('image-with-random-alt-tag')) }) -test('still works after browser page load and reload', async t => { +test('still works after browser page load and reload', async (t) => { await t.click(screen.getByText('Go to Page 2')) await t.eval(() => location.reload(true)) @@ -152,7 +151,7 @@ import { within, screen } from '@testing-library/testcafe' fixture`within`.page`http://localhost:13370` -test('works with getBy* selectors', async t => { +test('works with getBy* selectors', async (t) => { await t .expect( within(screen.getByTestId('nested')).getByText('Button Text').exists @@ -160,18 +159,18 @@ test('works with getBy* selectors', async t => { .ok() }) -test('works with CSS selector strings', async t => { +test('works with CSS selector strings', async (t) => { const { getByText } = await within('#nested') await t.click(getByText('Button Text')).ok() }) -test('works on any testcafe selector', async t => { +test('works on any testcafe selector', async (t) => { const nested = Selector('#nested') await t.expect(within(nested).getByText('Button Text').exists).ok() }) -test('works with results from "byAll" query with index - regex', async t => { +test('works with results from "byAll" query with index - regex', async (t) => { const nestedDivs = screen.getAllByTestId(/nested/) await t.expect(nestedDivs.count).eql(2) diff --git a/docs/vue-testing-library/faq.mdx b/docs/vue-testing-library/faq.mdx index 936a2421b..3b98cdd03 100644 --- a/docs/vue-testing-library/faq.mdx +++ b/docs/vue-testing-library/faq.mdx @@ -7,7 +7,7 @@ See also the [main FAQ](dom-testing-library/faq.mdx) for questions not specific to Vue testing.
-Is Vue Testing Library a replacement for the official @vue/test-utils? + Is Vue Testing Library a replacement for the official @vue/test-utils? Short answer: yes, it is. If you use Vue Testing Library (VTL) there's no need to install [@vue/test-utils][vue-test-utils]. @@ -20,7 +20,7 @@ methods in the [API](vue-testing-library/api.mdx) section.
-Do I need to install DOM Testing Library? + Do I need to install DOM Testing Library? Nope! VTL imports everything it needs from DOM Testing Library, and then re-exports it. @@ -28,7 +28,7 @@ re-exports it.
-What queries does Vue Testing Library provide? + What queries does Vue Testing Library provide? All queries from DOM Testing Library. See [Queries](dom-testing-library/api-queries.mdx) for full list. @@ -36,7 +36,7 @@ All queries from DOM Testing Library. See
-If I can't use shallow rendering, how do I mock out components in tests? + If I can't use shallow rendering, how do I mock out components in tests? In general, you should avoid mocking out components (see [the Guiding Principles section](guiding-principles.mdx)). @@ -62,11 +62,10 @@ VTL.
-How can I test if an element has appeared / has disappeared? + How can I test if an element has appeared / has disappeared? -Check the -[Appearance and Disappearance](guide-disappearance.mdx) -section of the Guide for available methods to test appearance and disappearance. +Check the [Appearance and Disappearance](guide-disappearance.mdx) section of the +Guide for available methods to test appearance and disappearance. If you want to check if an element was never rendered, you might want to write something like the following: diff --git a/package-lock.json b/package-lock.json index f33102649..dcde07a72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10262,9 +10262,9 @@ "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=" }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", + "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", "dev": true }, "pretty-error": { diff --git a/package.json b/package.json index 7ddd654af..eda4851d0 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "write-translations": "docusaurus-write-translations", "version": "docusaurus-version", "rename-version": "docusaurus-rename-version", - "format-docs": "prettier --write '../docs/**/*.mdx'", + "format-docs": "prettier --write 'docs/**/*.mdx' --parser=mdx", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "docusaurus": "docusaurus" @@ -18,14 +18,22 @@ "devDependencies": { "husky": "^1.3.1", "lint-staged": "^8.1.0", - "prettier": "^1.15.3" + "prettier": "^2.2.1" }, "lint-staged": { "linters": { - "*.js": ["prettier --write", "git add"], - "../docs/**/*.mdx": ["prettier --write --parser=markdown", "git add"], - "*.mdx": ["prettier --write --parser=markdown", "git add"], - "*.json": ["prettier --write --parser=json", "git add"] + "*.js": [ + "prettier --write", + "git add" + ], + "*.mdx": [ + "prettier --write --parser=mdx", + "git add" + ], + "*.json": [ + "prettier --write --parser=json", + "git add" + ] } }, "husky": {