@lynx-js/react/testing-library
ReactLynx Testing Library 是一个简单而完备的 ReactLynx 单元测试库,鼓励良好的测试实践。
完全受 react-testing-library 启发
和 react-testing-library 一样,这个库的设计目标是让你用测试 React 组件的方式来测试 ReactLynx 组件。
Setup
Rstest
用 @lynx-js/react/testing-library/rstest-config 配置 rstest。
推荐库项目使用:
想复用应用的 lynx.config.ts 时,使用 withLynxConfig:
withLynxConfig 和 withDefaultConfig 的区别:
withLynxConfig:面向应用。读取你的lynx.config.ts并转换成 rstest 配置,让 rspeedy/lynx 的设置在测试中同样生效。withDefaultConfig:面向库。只应用 testing-library 的默认配置(jsdom、setup 文件、全局变量),其余部分由你通过modifyRstestConfig提供。
然后就可以开始写测试,并用 rstest 运行它们了!
更多用法详见 https://rstest.rs/
Vitest
配置 vitest:
然后就可以开始写测试,并用 vitest 运行它们了!
createVitestConfig 仍然可用以保持向后兼容,但已废弃。
Usage
💡 由于我们的测试环境(@lynx-js/testing-environment)基于 jsdom,你可能还想安装 @testing-library/jest-dom,以便使用这些自定义 jest matcher。
Examples
更多用法参见我们的示例。
Credits
- Testing Library,提供了测试工具和 React 测试的良好实践。
命名空间
类
接口
- ByRoleOptions
- Config
- ConfigFn
- DefaultNormalizerOptions
- LogRolesOptions
- MatcherOptions
- NormalizerOptions
- PrettyDOMOptions
- Queries
- QueryOptions
- RenderHookOptions
- RenderHookResult
- RenderOptions
- SelectorMatcherOptions
- Suggestion
- waitForOptions
类型别名
- AllByAttribute
- AllByBoundAttribute
- AllByRole
- AllByText
- BoundFunction
- BoundFunctions
- BuiltQueryMethods
- ByRoleMatcher
- CreateFunction
- CreateObject
- ElementTree
- EventType
- FindAllBy
- FindAllByBoundAttribute
- FindAllByRole
- FindAllByText
- FindBy
- FindByBoundAttribute
- FindByRole
- FindByText
- FireFunction
- FireObject
- GetAllBy
- GetBy
- GetByBoundAttribute
- GetByRole
- GetByText
- GetErrorFunction
- Match
- Matcher
- MatcherFunction
- Method
- NormalizerFn
- Query
- QueryArgs
- QueryBy
- QueryByAttribute
- QueryByBoundAttribute
- QueryByRole
- QueryByText
- QueryMethod
- RenderResult
- Screen
- Variant
- WithSuggest
变量
函数
- act
- buildQueries
- cleanup
- computeHeadingLevel
- configure
- findAllByAltText
- findAllByDisplayValue
- findAllByLabelText
- findAllByPlaceholderText
- findAllByRole
- findAllByTestId
- findAllByText
- findAllByTitle
- findByAltText
- findByDisplayValue
- findByLabelText
- findByPlaceholderText
- findByRole
- findByTestId
- findByText
- findByTitle
- getAllByAltText
- getAllByDisplayValue
- getAllByLabelText
- getAllByPlaceholderText
- getAllByRole
- getAllByTestId
- getAllByText
- getAllByTitle
- getByAltText
- getByDisplayValue
- getByLabelText
- getByPlaceholderText
- getByRole
- getByTestId
- getByText
- getByTitle
- getConfig
- getDefaultNormalizer
- getElementError
- getNodeText
- getQueriesForElement
- getRoles
- getSuggestedQuery
- isInaccessible
- logDOM
- logRoles
- prettyDOM
- queryAllByAltText
- queryAllByDisplayValue
- queryAllByLabelText
- queryAllByPlaceholderText
- queryAllByRole
- queryAllByTestId
- queryAllByText
- queryAllByTitle
- queryByAltText
- queryByDisplayValue
- queryByLabelText
- queryByPlaceholderText
- queryByRole
- queryByTestId
- queryByText
- queryByTitle
- render
- renderHook
- waitFor
- waitForElementToBeRemoved
waitSchedule