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 'hasOwnProperty' of undefined #24

Open
gastonfartek opened this issue Mar 23, 2019 · 2 comments
Open

TypeError: Cannot read property 'hasOwnProperty' of undefined #24

gastonfartek opened this issue Mar 23, 2019 · 2 comments

Comments

@gastonfartek
Copy link

I am getting a TypeError: Cannot read property 'hasOwnProperty' of undefined
at

import { Adapter } from "enzyme-adapter-preact"

node_modules/enzyme-adapter-preact/node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js:276:27 at Object.<anonymous> (node_modules/enzyme-adapter-preact/node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js:943:5) at Object.<anonymous> (node_modules/enzyme-adapter-preact/node_modules/react-test-renderer/shallow.js:6:20) at Object.<anonymous> (node_modules/enzyme-adapter-preact/lib/PreactAdapter.js:20:16) at Object.<anonymous> (node_modules/enzyme-adapter-preact/lib/index.js:7:22)

@gastonfartek
Copy link
Author

I noticed that node_modules/enzyme-adapter-preact/lib/PreactAdapter.js:20:16 was requiring react-test-renderer/shallow, so I added this to my jest.config and it seems to have fixed the issue:

 moduleNameMapper: {
  //...
  "^react-test-renderer/shallow$": "preact-test-utils"`
}

However, are there any downsides about that approach?

@ijones922
Copy link

ijones922 commented May 15, 2019

Getting the same issue,

TypeError: Cannot read property 'hasOwnProperty' of undefined

      1 | const configure = require('enzyme').configure;
    > 2 | const Adapter = require('enzyme-adapter-preact');
        |               ^
      3 |
      4 | configure({ adapter: new Adapter() });
      5 |

      at node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js:276:27
      at Object.<anonymous> (node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js:943:5)
      at Object.<anonymous> (node_modules/react-test-renderer/shallow.js:6:20)
      at Object.<anonymous> (node_modules/enzyme-adapter-preact/lib/PreactAdapter.js:20:16)
      at Object.<anonymous> (node_modules/enzyme-adapter-preact/lib/index.js:7:22)
      at Object.<anonymous> (jest.setup.js:2:15)

I added this to my jest.config, but does not resolve the issue:

moduleNameMapper: {
		"react-dom/server": "preact-render-to-string",
		"react-dom/test-utils": "preact-test-utils",
		"react-dom": "preact-compat-enzyme",
		"^react-test-renderer/shallow$": "preact-test-utils"
		"react-test-renderer": "preact-test-utils",
		"react-addons-test-utils": "preact-test-utils",
		"react-addons-transition-group": "preact-transition-group",
		"react": "preact-compat-enzyme"
	}

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