@lynx-js/react/testing-library
ReactLynx Testing Library is a simple and complete ReactLynx unit testing library that encourages good testing practices.
Inspired completely by react-testing-library
Similar to react-testing-library, this library is designed to test your ReactLynx components in the same way you would test React components using react-testing-library.
Setup
Rstest
Setup rstest with @lynx-js/react/testing-library/rstest-config.
Recommended for library projects:
Use withLynxConfig when you want to reuse your app's lynx.config.ts:
Difference between withLynxConfig and withDefaultConfig:
withLynxConfig: app-oriented. Loads yourlynx.config.tsand converts it to rstest config, so rspeedy/lynx settings are reused in tests.withDefaultConfig: library-oriented. Only applies testing-library defaults (jsdom, setup files, globals) and lets you provide the rest viamodifyRstestConfig.
Then you can start writing tests and run them with rstest!
For more usage detail, see https://rstest.rs/
Vitest
Setup vitest:
Then you can start writing tests and run them with vitest!
createVitestConfig is still supported for backward compatibility, but is deprecated.
Usage
💡 Since our testing environment (@lynx-js/testing-environment) is based on jsdom, You may also be interested in installing @testing-library/jest-dom so you can use
the custom jest matchers.
Examples
See our examples for more usage.
Credits
- Testing Library for the testing utilities and good practices for React testing.
参考
prettyFormat
重命名并重新导出 act
QueryByBoundAttribute
QueryByRole
重新导出 QueryByRole
QueryByText
重新导出 QueryByText
QueryMethod
重新导出 QueryMethod
SelectorMatcherOptions
WithSuggest
重新导出 WithSuggest