我正在使用Jest和酶来测试一些React组件(使用TypeScript编写)。我的旧方法是使用酶的.simulate()函数来模拟点击,但为了支持使用实例属性函数(即只使用组件的onClick()属性),这种方法被弃用了。但是,我不确定如何准确地直接调用onClick()函数。下面是我的代码: // Get the onClick function
const buttonOnClick = wrapper.find('#diffpicker-button').first().props().onClick;
// buttonOnClick could be a fu
我有一个测试用例,该测试用例失败并提供了错误:
Expected value to be (using ===):
true
Received:
false
我不明白为什么,组件具有带有true false的属性,并且结果dom应该是正确的。
是什么导致了这个问题?
怎样才能看出什么是玩笑和酶的比较?
import React from 'react'
import { shallow } from 'enzyme'
import Location from './Location'
des
我正在遵循的酶示例和这个GitHub 示例来获得一个基本组件来测试和验证最外层的元素className是否存在,我不明白为什么这个不能通过:
// REACT组件
class VisitorShortcut extends Component {
//all the props & lifecycle hooks here
render() {
return (
<div className="visitor-shortcuts"> // <-- this className is being tested
我得到一个错误,最终崩溃了一个反应组件的测试。我使用阿波罗钩子突变useMutation和酶的成分发现通过id。
repo code\node_modules\react-dom\cjs\react-dom.development.js:154
var evt = document.createEvent('Event'); // Keeps track of whether the user-provided callback threw an error. We
^
TypeError: Cannot read
我在使用usestate()钩子进行状态操作后遇到问题。
无法编译错误:
./src/App.js
Line 6:43: React Hook "useState" is called in function "app" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks
Line 14:39: React Hook "useState" is called in functio
我的组件如下
import React from 'react';
import { connect } from 'react-redux';
import { Button } from 'react-bootstrap';
import UserActions from '../../../actions/sampleUserAction';
import UserForm from '../../../views/sample/userForm';
import UsersList from '.
我写了一个有趣的酶测试如下:
import React from 'react';
import ManageDrugTermPage from '../js/manageDrugTermPage.jsx';
import toJson from 'enzyme-to-json';
describe('manage drug term page test suite', () => {
it('snapshot test', () => {
const setRouteLeaveHook =
我正在尝试学习酶+ Jest反应组分的测试,我在酶中使用.find方法时出错了。
误差
Method “simulate” is meant to be run on 1 node. 0 found instead.
19 | onAddNew={onAddNew} />);
20 |
> 21 | component.find('button.btn-primary').simulate('click');
|