我一直在试着让摩卡和“反应本地人”合作。这是我到目前为止所做的工作(遵循Mocha文档):
-added测试文件夹
-added测试文件夹中的test.js文件
-added --对test.js文件的简单测试
var assert = require("assert");
describe('Array', function() {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', fun
我原本是做mocha/chai测试的。它很好,直到我尝试使用react simulate,然后mocha/chai似乎停止工作。现在我甚至不知道有多少测试通过或失败了。
对于我的一些测试用例,他们不断返回以下内容:
Error: Actions must be plain objects. Use custom middleware for async actions.
我有DetailPanel组件,其中包含带有title属性的Detail组件。
import React from 'react';
import Detail from './Detail';
import InfoTable from './InfoTable';
import EdgeIcon from './EdgeIcon';
import styles from './DetailsPanel.css';
export default class DetailsPanel extends React.
我刚开始测试React/类型记录应用程序。
命令(别名为react-scripts test):
yarn test
产出:
FAIL src/containers/pages/Feature/Feature.test.tsx
● Test suite failed to run
Target container is not a DOM element.
17 | const { store, persistor } = configureStore(history, initialState);
18 |
> 19 | React
我在我的项目中使用了Redux,用于测试堆栈是Mocha、柴和Sinon。在一个特定的容器组件ABC的componentDidMount中,发送一个动作xyz。在ABC的单元测试中,我想检查是否调用了xyz。ABC< code >E29</code>的代码>
import {xyz} from 'action';
class ABC extends React.Component {
componentDidMount(){
// some other magic
this.props.xyz();
}
render(
我正在为我正在制作的库编写一些测试。这不是一个项目,而是由babel从零开始构建的。我在开玩笑,我有这个问题。我看到了类似的问题,但没有像这样。在我的"test": "jest"脚本中有package.json。根文件夹中有一个__tests__目录。我的一个名为Component.js的测试文件从一些简单的导入开始:
import React from 'react';
import { MyComponent } from '../src/MyComponent.js';
当我运行npm run test时,会得到以下错误: