Skip to content

Instantly share code, notes, and snippets.

@Telematica
Last active October 12, 2024 03:46
Show Gist options
  • Save Telematica/c597c0e6e0d824ea4d551442fc96e08c to your computer and use it in GitHub Desktop.
Save Telematica/c597c0e6e0d824ea4d551442fc96e08c to your computer and use it in GitHub Desktop.
React Testing Library Recipies

React Testing Library Recipies with LOVE

Changelog:

  • toHaveTextContent
// 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