This repository has been archived by the owner on Dec 26, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I'm not expert of testing, so maybe I'm wrong with some parts.
Anyone wants to know my testing style in React, see my recent toy project.
testID
should considered as last option. Testing should be close to actual user.See Guiding Principles and How Should I Query?.
Actually, as I know,
getByRole
is number 1 priority in React-Testing-Libary. But it saidgetByText
is number 1. I guess it's becausegetByRole
is not that useful in RN(compare to React).For example, code below is used lot more than
Button
. But below code can't be queried withgetByRole('button')
.const
,beforeEach
,mockClear
, and given(it is not used here.)See this article.
I will write some testing guide in the future. So maybe this is enough here.
Related Issues
I mentioned about snapshot testing in #42.
Tests
I rewrite existing test.
Help / Discussion
There's no
toHaveStyle
property inJestMatchers<ReactTestInstance>
warning.I think It's related to type. But I install
@testing-library/jest-native
, which includes type(as I know).I don't know how to solve this.
Why
createTestProps
is needed?I found that (in this case) test doesn't breaks without it.
I don't know lot about React Native. So if you give me some context or explanation, I'll be thankful.
Why
createComponent
is needed?I think calling
createComponent
and wrap withThemeProvider
has very little difference in code size, but later is more clear and flexible as I did here.Checklist
yarn test
oryarn test -u
if you need to update snapshot.yarn lint