mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
add tests for TextInput.onChange and TextInput.onChangeText (#48899)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48899 changelog: [internal] Add tests for `TextInput.onChange` and `TextInput.onChangeText`. Reviewed By: rubennorte Differential Revision: D68498998 fbshipit-source-id: 212bc251700b343f7290fb7e2a5f2ddfdb68dfd1
This commit is contained in:
1 parent
7df73eebdc
commit
56a60601da
1 file changed
+68
+68
@@ -147,3 +147,71 @@ describe('focus and blur event', () => {
|
||||
expect(blurEvent).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onChange', () => {
|
||||
it('delivers onChange event', () => {
|
||||
const root = Fantom.createRoot();
|
||||
let maybeNode;
|
||||
const onChange = jest.fn();
|
||||
|
||||
Fantom.runTask(() => {
|
||||
root.render(
|
||||
<TextInput
|
||||
onChange={event => {
|
||||
onChange(event.nativeEvent);
|
||||
}}
|
||||
ref={node => {
|
||||
maybeNode = node;
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
const element = ensureInstance(maybeNode, ReactNativeElement);
|
||||
|
||||
Fantom.runOnUIThread(() => {
|
||||
Fantom.dispatchNativeEvent(element, 'change', {
|
||||
text: 'Hello World',
|
||||
});
|
||||
});
|
||||
|
||||
Fantom.runWorkLoop();
|
||||
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
const [entry] = onChange.mock.lastCall;
|
||||
expect(entry.text).toEqual('Hello World');
|
||||
});
|
||||
});
|
||||
|
||||
describe('onChangeText', () => {
|
||||
it('delivers onChangeText event', () => {
|
||||
const root = Fantom.createRoot();
|
||||
let maybeNode;
|
||||
const onChangeText = jest.fn();
|
||||
|
||||
Fantom.runTask(() => {
|
||||
root.render(
|
||||
<TextInput
|
||||
onChangeText={onChangeText}
|
||||
ref={node => {
|
||||
maybeNode = node;
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
const element = ensureInstance(maybeNode, ReactNativeElement);
|
||||
|
||||
Fantom.runOnUIThread(() => {
|
||||
Fantom.dispatchNativeEvent(element, 'change', {
|
||||
text: 'Hello World',
|
||||
});
|
||||
});
|
||||
|
||||
Fantom.runWorkLoop();
|
||||
|
||||
expect(onChangeText).toHaveBeenCalledTimes(1);
|
||||
const [entry] = onChangeText.mock.lastCall;
|
||||
expect(entry).toEqual('Hello World');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user