question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'contextTypes' of undefined

See original GitHub issue

I have installed enzyme with jest and running test cases as following

describe("Home", () => {
    it("should render correctly", () => {
        const component = shallow(<Home/>);
    });
});

error is: ● Home › should render correctly

TypeError: Cannot read property 'contextTypes' of undefined

   5 | describe("Home", () => {
   6 |     it("should render correctly", () => {
>  7 |         const component = shallow(<Home/>);
     |                           ^
   8 |     });
   9 |
  10 | });

  at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:633:54)
  at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
  at shallow (node_modules/enzyme/src/shallow.js:10:10)
  at Object.it (src/home/Home.test.js:7:27)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
zhenyu0519commented, Apr 14, 2020

I have installed enzyme with jest and running test cases as following

describe("Home", () => {
    it("should render correctly", () => {
        const component = shallow(<Home/>);
    });
});

error is: ● Home › should render correctly

TypeError: Cannot read property 'contextTypes' of undefined

   5 | describe("Home", () => {
   6 |     it("should render correctly", () => {
>  7 |         const component = shallow(<Home/>);
     |                           ^
   8 |     });
   9 |
  10 | });

  at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:633:54)
  at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
  at shallow (node_modules/enzyme/src/shallow.js:10:10)
  at Object.it (src/home/Home.test.js:7:27)

You need export your component properly, please check your component export. How do you export it?

2reactions
chulijimmicommented, Mar 2, 2020

@ljharb Yes dude, its solve, you right its props undefined, so need to mountWithProvide in the first step. Ya I think this issued should closed, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'contextTypes' of undefined
Here is an example: AccountFormComponent.jsx (incorrect class name): export class FoeFormComponent extends React.Component { .... }.
Read more >
Jest Test Redux Thunk TypeError: Cannot read property ...
Jest Test Redux Thunk TypeError: Cannot read property 'contextTypes' of undefined. export your Component. for example, export const UnConnectedMyComponent ...
Read more >
Cannot read property 'contextTypes' of undefined Unit Testing ...
Coding example for the question Cannot read property 'contextTypes' of undefined Unit Testing enzyme-Reactjs.
Read more >
Uncaught typeerror: cannot read property 'type' of undefined
Uncaught TypeError: Cannot read property 'type' of undefined ,. Out of the six primitive types defined in JavaScript, namely boolean, string, symbol, number, ......
Read more >
typeerror: cannot read property 'location' of undefined jest
A child component is utilizing a tab from material UI, however, every time I run the test the error TypeError: Cannot read property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found