Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't simulate press event in react-native #991

Closed
cigdemgullu opened this issue Jun 19, 2017 · 3 comments
Closed

Can't simulate press event in react-native #991

cigdemgullu opened this issue Jun 19, 2017 · 3 comments

Comments

@cigdemgullu
Copy link

We have implemented NativeBase's CheckBox where you can find here.
It simply iterates over a list and return a set of ListItems which contains CheckBox.
We are trying to write unit test of this component and stuck at simulation of press event.
The press event is bind to ListItems. You can find the test code below. Having trouble testing pressevent.

import * as React from 'react'
import { mount } from 'enzyme'
import * as chai from 'chai'
import { ListItem } from 'native-base'

it('onPress()', () => {
        const wrapper = mount(getComponent(commonProps))
        wrapper.find(ListItem).first().simulate('press')
})

And the console output is

TypeError: ReactWrapper::simulate() event 'press' does not exist

We appreciate any feedback about event simulation.

@rndmerle
Copy link

rndmerle commented Jul 5, 2017

Just to be sure, because you're using press you're under React-Native?
Does wrapper.find(ListItem).first().props().onPress() work?

@ljharb
Copy link
Member

ljharb commented Jul 5, 2017

In general, I've found it's best to invoke the prop directly and avoid .simulate.

@cigdemgullu
Copy link
Author

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants