在更新到npm 3.3.12之后,使用Jest进行unit testing时出错
我最近更新了我的项目到节点5.1.0,npm 3.3.12,并更新了我所有的依赖…现在我正在对付一堆错误!
最初我在这个问题上有同样的错误: https : //github.com/facebook/jest/issues/554 ,很容易修复。
Bur现在我得到这个:
警告:React.createElement:types不应该是null,undefined,boolean或number。 它应该是一个string(对于DOM元素)或ReactClass(对于复合组件)。
和
错误:不变违规:元素types无效:期望一个string(对于内置组件)或一个类/函数(对于复合组件),但得到:对象。
我有这在我的package.json:
"jest": { "collectCoverage": true, "testRunner": "./node_modules/jest-cli/src/testRunners/jasmine/jasmine2", "scriptPreprocessor": "./node_modules/babel-jest", "unmockedModulePathPatterns": [ "./node_modules/es6-promise", "./node_modules/events", "./node_modules/fbjs", "./node_modules/flux", "./node_modules/history", "./node_modules/immutable", "./node_modules/lodash", "./node_modules/moment", "./node_modules/react", "./node_modules/react-addons-pure-render-mixin", "./node_modules/react-addons-test-utils", "./node_modules/react-d3", "./node_modules/react-dom", "./node_modules/react-modal", "./node_modules/react-router", "./node_modules/whatwg-fetch" ] }
我的testing的相关部分是:
var ImageGallery = require('../../../app/components/image-gallery/image-gallery'); imageGalleryComponent = TestUtils.renderIntoDocument( <ImageGallery items={items} onSlide={onSlideMock} lazyLoad={false} showBullets={true} showThumbnails={true} showNav={true} slideInterval={4000}/> );
任何人遇到这个问题? 任何线索如何解决?
在我的代码中,我使用babel和“imports”,所以问题是在testing中我需要使用“imports”,或者在require语句的末尾添加一个“.default”,如下所示:
var ImageGallery = require('../../../app/components/image-gallery/image-gallery').default;
- 为什么Node fs.watchFile保持testing完成?
- 如何使用iron-node来debugging玩笑unit testing?
- 用笑话嘲笑mongoose模型
- reactJs Jest:`jsdom 4.x以前只能用于io.js,而不是Node.jsT:
- Jest错误:无法获取模拟元数据:node_modules / core-js / modules / $。global.js
- React组件在浏览器中正确渲染,但Jesttesting时出现错误:“只有ReactOwner可以引用”
- Jest,Typescript,ts-jest:覆盖率稍微不正确
- 笑话 – 有没有办法检查testing覆盖率的百分比?
- 使用TFS 2015运行Jestunit testing