samedi 25 février 2017

React Native Jest Enzyme Find and Press Component

i'm trying to be adventurous and im trying to get 100% code coverage on my personal project. and i cant the documentation that explains how to simulate a click event using jest, enzyme and react-native.

<Screen.TopBar>
    <Toolbar
        leftElement="arrow-back"
        onLeftElementPress={() => router.pop()}
        centerElement={pageName}
    />
</Screen.TopBar>

this is just the top part of it, but im trying to simulate a click on that element.

const wrapper = mount(
    <MockProvider store={store}>
        <ThemeProvider uiTheme={uiTheme}>
            <Category />
        </ThemeProvider>
    </MockProvider>
);
expect(wrapper.find('Toolbar').length).toBe(1);

i get an error:

ReferenceError: document is not defined

  at Object.renderIntoDocument (node_modules/react-dom/lib/ReactTestUtils.js:73:15)
  at renderWithOptions (node_modules/enzyme/build/react-compat.js:187:26)
  at new ReactWrapper (node_modules/enzyme/build/ReactWrapper.js:94:59)
  at mount (node_modules/enzyme/build/mount.js:19:10)
  at Object.<anonymous> (app/screens/category/tests/Category.test.js:32:30)

so my question is how do i select the toolbar so that i can click on the button in the Toolbar component.

Aucun commentaire:

Enregistrer un commentaire