This repository was archived by the owner on Jul 30, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 44
fix(getBy*): throw an error if more than one element is found #7
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
61895c9
feat(queries): throw when multiple elements are returned from getBy
9e226cf
refactor: use new query abstractions
bcarroll22 921d90b
chore: bump test coverage to 100%
bcarroll22 1bb9f9a
fix: change wording on comments
bcarroll22 94a1349
fix: be consistent with checking for exceptions
bcarroll22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
import React from 'react'; | ||
import { Text, TextInput, View } from 'react-native'; | ||
import cases from 'jest-in-case'; | ||
|
||
import { render } from '../'; | ||
|
||
cases( | ||
'getBy* queries throw an error when there are multiple elements returned', | ||
({ name, query, tree }) => { | ||
const utils = render(tree); | ||
expect(() => utils[name](query)).toThrow(/multiple elements/i); | ||
}, | ||
{ | ||
getByA11yHint: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<View accessibilityHint="his" /> | ||
<View accessibilityHint="history" /> | ||
</View> | ||
), | ||
}, | ||
getByA11yLabel: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<View accessibilityLabel="his" /> | ||
<View accessibilityLabel="history" /> | ||
</View> | ||
), | ||
}, | ||
getByA11yRole: { | ||
query: 'button', | ||
tree: ( | ||
<View> | ||
<View accessibilityRole="button" /> | ||
<View accessibilityRole="button" /> | ||
</View> | ||
), | ||
}, | ||
getByA11yStates: { | ||
query: ['selected'], | ||
tree: ( | ||
<View> | ||
<View accessibilityStates={['selected']} /> | ||
<View accessibilityStates={['selected']} /> | ||
</View> | ||
), | ||
}, | ||
getByA11yTraits: { | ||
query: ['button'], | ||
tree: ( | ||
<View> | ||
<View accessibilityTraits={['button']} /> | ||
<View accessibilityTraits={['button']} /> | ||
</View> | ||
), | ||
}, | ||
getByPlaceholder: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<TextInput placeholder="his" /> | ||
<TextInput placeholder="history" /> | ||
</View> | ||
), | ||
}, | ||
getByTestId: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<Text testID="his">text</Text> | ||
<Text testID="history">other</Text> | ||
</View> | ||
), | ||
}, | ||
getByText: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<Text>his</Text> | ||
<Text>history</Text> | ||
</View> | ||
), | ||
}, | ||
getByValue: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<TextInput value="his" /> | ||
<TextInput value="history" /> | ||
</View> | ||
), | ||
}, | ||
}, | ||
); | ||
|
||
cases( | ||
'queryBy* queries throw an error when there are multiple elements returned', | ||
({ name, query, tree }) => { | ||
const utils = render(tree); | ||
expect(() => utils[name](query)).toThrow(/multiple elements/i); | ||
}, | ||
{ | ||
queryByA11yHint: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<View accessibilityHint="his" /> | ||
<View accessibilityHint="history" /> | ||
</View> | ||
), | ||
}, | ||
queryByA11yLabel: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<View accessibilityLabel="his" /> | ||
<View accessibilityLabel="history" /> | ||
</View> | ||
), | ||
}, | ||
queryByA11yRole: { | ||
query: 'button', | ||
tree: ( | ||
<View> | ||
<View accessibilityRole="button" /> | ||
<View accessibilityRole="button" /> | ||
</View> | ||
), | ||
}, | ||
queryByA11yStates: { | ||
query: ['selected'], | ||
tree: ( | ||
<View> | ||
<View accessibilityStates={['selected']} /> | ||
<View accessibilityStates={['selected']} /> | ||
</View> | ||
), | ||
}, | ||
queryByA11yTraits: { | ||
query: ['button'], | ||
tree: ( | ||
<View> | ||
<View accessibilityTraits={['button']} /> | ||
<View accessibilityTraits={['button']} /> | ||
</View> | ||
), | ||
}, | ||
queryByPlaceholder: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<TextInput placeholder="his" /> | ||
<TextInput placeholder="history" /> | ||
</View> | ||
), | ||
}, | ||
queryByTestId: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<Text testID="his">text</Text> | ||
<Text testID="history">other</Text> | ||
</View> | ||
), | ||
}, | ||
queryByText: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<Text>his</Text> | ||
<Text>history</Text> | ||
</View> | ||
), | ||
}, | ||
queryByValue: { | ||
query: /his/, | ||
tree: ( | ||
<View> | ||
<TextInput value="his" /> | ||
<TextInput value="history" /> | ||
</View> | ||
), | ||
}, | ||
}, | ||
); |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
|
||
import { render } from '../'; | ||
import { queryByProp } from '../'; | ||
|
||
// we used to use queryByProp internally, but we don't anymore. Some people | ||
// use it as an undocumented part of the API, so we'll keep it around. | ||
test('queryByProp', () => { | ||
const { container } = render( | ||
<View> | ||
<View importantForAccessibility="no" /> | ||
<View importantForAccessibility="no-hide-descendants" /> | ||
</View>, | ||
); | ||
|
||
expect(queryByProp('importantForAccessibility', container, 'no')).not.toBeNull(); | ||
expect(queryByProp('importantForAccessibility', container, 'auto')).toBeNull(); | ||
expect(() => queryByProp('importantForAccessibility', container, /no/)).toThrow(/multiple/); | ||
}); |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.