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

TypeError: Cannot read property 'actionTypes' of undefined #973

Closed
andrewmclagan opened this issue May 6, 2016 · 3 comments
Closed

TypeError: Cannot read property 'actionTypes' of undefined #973

andrewmclagan opened this issue May 6, 2016 · 3 comments

Comments

@andrewmclagan
Copy link

andrewmclagan commented May 6, 2016

This is possibly related related to babel-jest settings, although I'm unable to debug the issue.

When importing a react component redux-form we are receiving the following error in our test:

FAIL  __tests__/FormComponent.test.js
● Runtime Error
TypeError: Cannot read property 'actionTypes' of undefined
    at Object.<anonymous> (/--REDACTED--/jest-react-example/node_modules/redux-form/lib/index.js:22:29)
    at Object.<anonymous> (/--REDACTED--/jest-react-example/FormComponent.js:3:42)
    at Object.<anonymous> (/--REDACTED--/jest-react-example/__tests__/FormComponent.test.js:8:46)
    at jasmine2 (/--REDACTED--/jest-react-example/node_modules/jest-jasmine2/src/index.js:231:16)
    at process._tickCallback (internal/process/next_tick.js:103:7)
npm ERR! Test failed.  See above for more details.

Following the stack trace to /--REDACTED--/jest-react-example/node_modules/redux-form/lib/index.js:22:29 its seems jest is having trouble mocking this components code.

We have setup a repository to replicate this issue: https://github.com/andrewmclagan/jest-react-example.

You will notice that we are not testing reduxForm we are exporting two things from our FormComponent file: an isolated component and the redux-form component. Currently from the docs its not clear how to deal with default es6 exports. Really we only want to test the isolated component.

As the component actually functions we are assuming its Jest related?

@andrewmclagan
Copy link
Author

andrewmclagan commented May 6, 2016

Pushed a branch no-stage-0 to isolate the issue further and still no luck. https://github.com/andrewmclagan/jest-react-example/tree/no-stage-0 ...

The only way to overcome this issue is to do a complete manual mock on the redux-form library. That way bypassing Jest having to auto-mock and thus breaking.

// File: /__mocks__/redux-form.js (project root, next to /node_modules/ )

export const reduxForm = () => Component => Component; 

export default jest.fn();

see the above in the mocked-package branch

@cpojer
Copy link
Member

cpojer commented May 14, 2016

It's likely because your setup is slightly wrong: https://github.com/andrewmclagan/jest-react-example/blob/no-stage-0/package.json#L22 here you should add a slash at the end: node_modules/react/ otherwise react-redux will also be mocked because this config option is just matched against the paths of all files.

Happy to reopen if this doesn't turn out to be the actual issue.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants