React Enzyme Type错误:无法读取属性'propTypes'的未定义
React Enzyme Type Error:Cannot read property 'propTypes' of undefined
以下是我的React组件:
import React from 'react'
var PageLeftLower = React.createClass({
render:function(){
return(<a href="#">Quote Requests</a>);
}
});
module.exports = PageLeftLower;
所以,非常简单的React组件。我刚刚开始使用Enzyme和Mocha进行测试,并编写了以下代码。
import expect from 'expect';
import React from 'react';
import {shallow} from 'enzyme';
import {PageLeftLower} from './PageLeftLower';
describe('Component : WholeTab',() => {
it('renders without exploding', () => {
expect(shallow(<PageLeftLower/>).length).toEqual(1);
});
});
当我执行它时,它会输出以下警告:
组件:WholeTab警告:React.createElement:type不应为null、undefined、boolean或number。它应该是字符串(对于DOM元素)或ReactClass(对于复合组件)。
以及以下错误:
TypeError:无法读取未定义的属性"propTypes"。
非常感谢您的帮助。
问题就在这里:
import {PageLeftLower} from './PageLeftLower';
因为您使用直接导出组件
module.exports = PageLeftLower;
它没有被包裹在这样的对象中:
module.exports = {PageLeftLower: PageLeftLower};
因此,您的组件可以通过以下方式访问:
import PageLeftLower from './PageLeftLower'; // not {PageLeftLower}
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS指令出错-无法读取属性'编译'的未定义
- 这.SOMETHING 总是返回未定义的 - extjs
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- Wordpress中带有JQuery Accordion的未定义匿名函数
- React Enzyme Type错误:无法读取属性'propTypes'的未定义