I have the following problem: I need to test if a function is being called on my test, but to test it properly I need to press enter or submit the form, and it doesn't seem to work as intended. I've already tried the following:
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' });
fireEvent.submit(input);
The only way to trigger the onSubmitEditing
prop of my component is by pressing the Enter key.
Here's the code I'm trying to test:
<Input placeholder="Cirurgião"
testID='input_buscaCirurgiao_index'
value={this.state.text}
autoCorrect={false}
keyboardType={(Platform.OS === 'android') ? 'visible-password' : 'default'}
onChangeText={(item) => this.setState({ text: item })}
onSubmitEditing={() => { this._searchPressingEnter() }} // i need to test this
autoCapitalize='none'
/>
Here's the code for the _searchPressingEnter
function:
_searchPressingEnter() {
Keyboard.dismiss()
let item = this.state.text
this._buscarCirurgioes(item)
}
Once the Enter key has been pressed, the _searchPressingEnter
function should be called, thus triggering the onSubmitEditing
prop.