【发布时间】:2021-12-11 07:46:47
【问题描述】:
我是新来的反应和开玩笑,我现在不使用酶
我面临的错误是没有重载匹配此调用。 'Overload 1 of 2, '(props: XProperty| Readonly ): BuildingUnit',给出了以下错误。 类型“{}”缺少“只读”类型的以下属性:ab、cd Overload 2 of 2, '(props: XProperty, context: any): BuildingUnit',给出了以下错误。 类型“{}”缺少“只读”类型的以下属性:ab、cd'
类 BuildingUnit:
type XProperty= { ab, cd};
type YProperty= {ef, gh};
class BuildingUnit extends React.Component<XProperty, YProperty>{
methodA(){
}
Method B(){
}
render(){
<input text onChange={this.MethodA}>
}
}
export default BuildingUnit;
当我尝试通过渲染从标签中获取文本时,它会引发错误“没有重载匹配此调用” 而且我还想知道如何在 BuildUnitTest 中访问 MethodA() 以进行断言 BuildUnit.test.js:
import BuildingUnit from './BuildingUnit';
import React, { useImperativeHandle } from 'react';
import * as ReactDOM from 'react-dom';
import { fireEvent, render, screen } from '@testing-library/react';
test('Validation', ()=>{
const root = document.createElement("div");
const {getByText, getByLabelText}= render(<BuildingUnit/>);
})
【问题讨论】:
-
听起来你真的有两个问题。如果我理解正确,您无法让组件工作,因为它认为它没有正确的道具?第二个问题是如何直接测试
MethodA?我想查看有关第一个问题的更多详细信息。我不清楚这是测试中的问题还是源代码本身的问题。 -
不,源代码运行良好,没有任何问题。它有正确的道具。但我的问题是当我尝试使用“渲染(
)”时,它给了我一个缺少道具类型的错误。那么如何在测试类中定义道具类型