我正在尝试在一个小应用程序中编写一些测试,这个小应用程序是我在React教程中编写的
我的堆栈
node -> v8.7.0
mocha -> "^5.1.0"
jsdom -> "^11.8.0"
jquery -> "^3.3.1"
react-dom -> "^16.3.2"
react -> "^16.3.2"
chai -> "^4.1.2"
babel-register -> "^6.26.0"
这是我的
test_helper
import { JSDOM } from 'jsdom';
import jquery from 'jquery';
import ReactTestUtils from 'react-dom/test-utils';
import React from 'react';
import ReactDOM from 'react-dom';
import { expect } from 'chai';
//Set up testing environment to run like a browser in the command line
const dom = new JSDOM('<!doctype html><html><body></body></html>');
global.window = dom.window;
global.document = dom.window.document;
const $ = jquery(global.window);
// Build a 'renderComponent' helper that should render a given react class
function renderComponent(ComponentClass) {
const componentInstance = ReactTestUtils.renderIntoDocument(<ComponentClass />);
return $(ReactDOM.findDOMNode(componentInstance));
}
//Build a helper for simulating events
//Set up chai-jquery
export { renderComponent, expect };
我的
board_test
import { renderComponent, expect } from '../test_helper';
import Board from '../../src/components/board';
describe('Board', () => {
it('exist', () => {
const component = renderComponent(Board);
expect(component).to.exist;
});
});
并且在
package.json
我有
...
"scripts": {
...
"test": "mocha --require babel-register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch"
}
...
当我跑步时
npm test
我得到这个错误,我知道这与renderComponent(…)有关
1) 董事会
存在:
TypeError:无法读取未定义的属性“0”
如果有人想下载该项目,请点击这里的链接(我面临的问题是
分支添加测试
)
My Repo
-&燃气轮机;
分支添加测试
更改为分支addTests
git checkout -b addTests origin/addTests