- toHaveTextContent
Last active
October 12, 2024 03:46
-
-
Save Telematica/c597c0e6e0d824ea4d551442fc96e08c to your computer and use it in GitHub Desktop.
React Testing Library Recipies
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
// References | |
// https://testing-library.com/docs/react-native-testing-library/example-intro/ | |
// https://github.com/testing-library/dom-testing-library/issues/410#issuecomment-1025614942 | |
// https://stackoverflow.com/a/65726104 | |
// Match text in nested tags: <span>Text <a>even more text</a></span> matches: /Text even more text/ | |
import * as React from 'react' | |
import '@testing-library/jest-dom/extend-expect'; | |
test('examples of some things', async () => { | |
const { container } = render(<Example />); | |
// Using `toHaveTextContent` matcher from `@testing-library/jest-native` package. | |
expect(container).toHaveTextContent(/Text stuff/) | |
expect(screen.toJSON()).toMatchSnapshot() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment