### Quickstart Test Implementation Source: https://github.com/testing-library/testing-library-docs/blob/main/docs/react-testing-library/example-intro.mdx A minimal test setup using React Testing Library and user-event to verify component behavior. ```jsx import {render, screen} from '@testing-library/react' import userEvent from '@testing-library/user-event' import '@testing-library/jest-dom' import Fetch from './fetch' test('loads and displays greeting', async () => { // ARRANGE render() // ACT await userEvent.click(screen.getByText('Load Greeting')) await screen.findByRole('heading') // ASSERT expect(screen.getByRole('heading')).toHaveTextContent('hello there') expect(screen.getByRole('button')).toBeDisabled() }) ``` ```jsx // import react-testing methods import {render, screen} from '@testing-library/react' // userEvent library simulates user interactions by dispatching the events that would happen if the interaction took place in a browser. import userEvent from '@testing-library/user-event' // add custom jest matchers from jest-dom import '@testing-library/jest-dom' // the component to test import Fetch from './fetch' test('loads and displays greeting', async () => { // Render a React element into the DOM render() await userEvent.click(screen.getByText('Load Greeting')) // wait before throwing an error if it cannot find an element await screen.findByRole('heading') // assert that the alert message is correct using // toHaveTextContent, a custom matcher from jest-dom. expect(screen.getByRole('heading')).toHaveTextContent('hello there') expect(screen.getByRole('button')).toBeDisabled() }) ``` -------------------------------- ### Input Tag Setup and Querying Source: https://github.com/testing-library/testing-library-docs/blob/main/docs/queries/bydisplayvalue.mdx Examples for setting an input value and querying it across different frameworks. ```html ``` ```javascript document.getElementById('lastName').value = 'Norris' ``` ```javascript import {screen} from '@testing-library/dom' const lastNameInput = screen.getByDisplayValue('Norris') ``` ```jsx import {render, screen} from '@testing-library/react' render() const lastNameInput = screen.getByDisplayValue('Norris') ``` ```typescript import {render, screen} from '@testing-library/angular' await render(MyComponent) const lastNameInput = screen.getByDisplayValue('Norris') ``` ```javascript cy.findByDisplayValue('Norris').should('exist') ``` -------------------------------- ### Select Tag Setup and Querying Source: https://github.com/testing-library/testing-library-docs/blob/main/docs/queries/bydisplayvalue.mdx Examples for querying a select element by its currently selected option. ```html ``` ```javascript import {screen} from '@testing-library/dom' const selectElement = screen.getByDisplayValue('Alaska') ``` ```jsx import {render, screen} from '@testing-library/react' render() const selectElement = screen.getByDisplayValue('Alaska') ``` ```typescript import {render, screen} from '@testing-library/angular' await render(MyComponent) const selectElement = screen.getByDisplayValue('Alaska') ``` ```javascript cy.findByDisplayValue('Alaska').should('exist') ``` -------------------------------- ### Install bs-platform Source: https://github.com/testing-library/testing-library-docs/blob/main/docs/bs-react-testing-library/intro.mdx Install the BuckleScript compiler if it is missing from the project. ```bash npm install --save-dev bs-platform ``` -------------------------------- ### Setup Function for userEvent Tests Source: https://github.com/testing-library/testing-library-docs/blob/main/docs/user-event/intro.mdx Define a `setup` function that initializes `userEvent.setup()` and renders the component. This centralizes setup logic and returns the user instance along with other render utilities. ```javascript import userEvent from '@testing-library/user-event' // setup function function setup(jsx) { return { user: userEvent.setup(), // Import `render` from the framework library of your choice. // See https://testing-library.com/docs/dom-testing-library/install#wrappers ...render(jsx), } } test('render with a setup function', async () => { const {user} = setup() // ... }) ``` -------------------------------- ### Setup Browser for Testing Library Queries Source: https://github.com/testing-library/testing-library-docs/blob/main/docs/webdriverio-testing-library/intro.mdx Use `setupBrowser` to integrate dom-testing-library queries into WebdriverIO. All queries are async and bound to `document.body` by default. This example demonstrates clicking a button and verifying its text. ```javascript import {setupBrowser} from '@testing-library/webdriverio' it('can click button', async () => { const {getByText} = setupBrowser(browser) const button = await getByText('Button Text') await button.click() expect(await button.getText()).toEqual('Button Clicked') }) ``` -------------------------------- ### Install Dependencies Source: https://github.com/testing-library/testing-library-docs/blob/main/README.md Run this command to install all necessary dependencies for the documentation website. ```sh # Install dependencies $ npm install ``` -------------------------------- ### Textarea Tag Setup and Querying Source: https://github.com/testing-library/testing-library-docs/blob/main/docs/queries/bydisplayvalue.mdx Examples for setting a textarea value and querying it across different frameworks. ```html