-
Notifications
You must be signed in to change notification settings - Fork 934
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react-native): don't crash with onBlur (#586)
* Add failing test for onBlur being called in react native environment * Check for document before trying to access document properties * Add to all contributors
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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,42 @@ | ||
import {Text, TextInput, View} from 'react-native' | ||
import React from 'react' | ||
|
||
// Note: test renderer must be required after react-native. | ||
import TestRenderer from 'react-test-renderer' | ||
|
||
import Downshift from '../../../dist/downshift.native.cjs' | ||
|
||
const RootView = ({innerRef, ...rest}) => <View ref={innerRef} {...rest} /> | ||
|
||
test('calls onBlur and does not crash when there is no document', () => { | ||
const Input = jest.fn(props => <TextInput {...props} />) | ||
|
||
const element = ( | ||
<Downshift> | ||
{({getRootProps, getInputProps, getItemProps}) => ( | ||
<RootView {...getRootProps({refKey: 'innerRef'})}> | ||
<Input {...getInputProps()} /> | ||
<View> | ||
<Text {...getItemProps({item: 'foo', index: 0})}>foo</Text> | ||
<Text {...getItemProps({item: 'bar', index: 1})}>bar</Text> | ||
</View> | ||
</RootView> | ||
)} | ||
</Downshift> | ||
) | ||
TestRenderer.create(element) | ||
|
||
const [[firstArg]] = Input.mock.calls | ||
expect(firstArg).toMatchObject({ | ||
onBlur: expect.any(Function), | ||
}) | ||
const fakeEvent = 'blur' | ||
firstArg.onBlur(fakeEvent) | ||
}) | ||
|
||
/* | ||
eslint | ||
react/prop-types: 0, | ||
import/extensions: 0, | ||
import/no-unresolved: 0 | ||
*/ |
This file contains 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