React JSX Question

TypeError: Cannot read property 'contextTypes' of undefined

I'm trying to testing a React-app with Jest, I use Enzyme's shallow to render my

component in
but I'm getting this error:
TypeError: Cannot read property 'contextTypes' of undefined

This is my

/* global google */
import React, { Component } from 'react';
import Geosuggest from 'react-geosuggest';
import { getAirQuality } from './Client'
import DataTable from './DataTable'
import Errors from 'react-errors'

class App extends Component {


render() {
return (
<div className="App">
<form onSubmit={this.searchAirQuality.bind(this)}>
placeholder="Type a location and press SEARCH button!"
location={new google.maps.LatLng(53.558572, 9.9278215)}
<button className="my-button" type="submit" disabled={!}>Button</button>
<DataTable items={this.state.items} />

export default App;

and This is my

import React from 'react'
import { shallow } from 'enzyme'
import App from '../components/App.js'

describe( '<App />', () => {
it('Button disable when input is empty', () => {
const App = shallow(<App />);




And this the error when I run
npm test

Terminal screenshot

Is my first time with testing in jest, please could someone help me with any idea about this error?

Answer Source

The problem here is that you are redefining the the app component with the result of the shallow call

//    Redefining
//    ↓
const App = shallow(<App />);

The solution here is to use a different name:

//    Use a different name
//    ↓
const app = shallow(<App />);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download