TypeError: Cannot read property 'contextTypes' of undefined
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 would be to use a different name:
// Use a different name
// ↓
const app = shallow(<App />);
This would be the same error TypeError: Cannot read property 'contextTypes' of undefined
when you are importing something that does not exist.
Here is an example:AccountFormComponent.jsx
(incorrect class name):
export class FoeFormComponent extends React.Component { .... }
AccountFormComponent.test.jsx
:
import { shallow } from 'enzyme'
import { expect, assert } from 'chai'
import { AccountFormComponent } from '../../src/components/AccountFormComponent';
describe('', function () {
it('', function () {
const enzymeWrapper = shallow(<AccountFormComponent {...props} />);
});
});
Just add the following to your test file to be sure the component exists:
it('should exists', function () {
assert.isDefined(AccountFormComponent);
});
which prints AssertionError: expected undefined to not equal undefined
instead