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

[Redux-toolkit] [createEntityAdapter] Cannot read property 'ids' of undefined #178

Open
daminhtung opened this issue Aug 3, 2020 · 1 comment

Comments

@daminhtung
Copy link

daminhtung commented Aug 3, 2020

Hi, I got an error when running the test. Any help or suggestions for me?

  • redux-mock-store: ^1.5.4
  • "@types/redux-mock-store": "^1.0.2",
  • "@reduxjs/toolkit": "^1.3.5",
  • "@testing-library/react-native": "^5.0.3",

Error when run testing

TypeError: Cannot read property 'ids' of undefined

  47 |   const items = useSelector((state: MyState) => {
> 48 |     return myEntityAdapter.getSelectors().selectAll(state.mystate)
        |                                         ^
  49 |   })
  50 | 

My test:

const { queryByTestId } = render(
      <Provider store={store}>
        <MenuProvider skipInstanceCheck={true}>
          <MyComponent />
        </MenuProvider>
      </Provider>
    )

mySlice.ts

...
export const myEntityAdapter = createEntityAdapter<Item>()
...
@leosuncin
Copy link

Pass an state to mockStore, like this:

import configureStore from 'redux-mock-store';

import type { RootState } from '../../app/store';

const mockStore = configureStore<RootState>();
const store = mockStore({ slice: { ids: [], entities: {} } });

// Rest of the test...

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

2 participants