Enzyme: Shallow with store context not work

Created on 20 Jan 2019  路  4Comments  路  Source: enzymejs/enzyme

API

  • [x] shallow
  • [ ] mount
  • [ ] render

Version

| library | version
| ------------------- | -------
| enzyme | "^3.8.0"
| react | "^16.7.0
| react-dom | "^16.7.0"
| react-test-renderer | "^16.7.0"
| adapter (below) | "^1.7.1"

My project/Teste component:

https://github.com/henriqueweiand/reactjs-crud-state-test/blob/master/src/pages/__tests__/formDocumentos.test.js

I'm having trouble connecting the test with the component to the test reports, I noticed that a lot of people posted some issue about it, but checking them out and running tests like these issues did not succeed. Anyway, I have a form and I need to connect it to the redux to give sequence in the tests, but in the way that I have implemented today, the return is:

Invariant Violation: Passing redux store in props has been removed and does not do anything. To use a custom Redux store for specific components, create a custom React context with React.createContext(), and pass the context object to React-Redux's Provider and specific components like: . You may also pass a {context : MyContext} option to connect

question

Most helpful comment

It looks like you're using react-redux v6, which i don't believe is ergonomically compatible with enzyme yet. Try v5.

All 4 comments

It looks like you're using react-redux v6, which i don't believe is ergonomically compatible with enzyme yet. Try v5.

Okay, I think we have a breakthrough, kkkk

I downgraded, but now I do not understand why my tests do not find the element to accomplish the simulate with click

I'm doing it this way:

fit('teste', () => {
    store = mockStore(INITIAL_STATE);
    wrapper = shallow(
      <FormDocumentos
        match={INITIAL_STATE.match}
        values={newDocumentos}
      />,
      { context: { store } },
    ).dive();

    wrapper.find('button').simulate('click');
    console.log(store.getActions());

  });

project: https://github.com/henriqueweiand/reactjs-crud-state-test/blob/master/src/pages/__tests__/formDocumentos.test.js

You're using shallow, and FormDocumentos renders a component that's wrapped in two HOCs - you need one .dive() per HOC, and you only have one.

This seems answered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blainekasten picture blainekasten  路  3Comments

heikkimu picture heikkimu  路  3Comments

ahuth picture ahuth  路  3Comments

benadamstyles picture benadamstyles  路  3Comments

abe903 picture abe903  路  3Comments