Jestjs Jest酶装入错误:引用一个值,但在此处用作类型ts(2749)
我正在开始测试,我真的被困在这件事里了 我有一个组件Jestjs Jest酶装入错误:引用一个值,但在此处用作类型ts(2749),jestjs,enzyme,Jestjs,Enzyme,我正在开始测试,我真的被困在这件事里了 我有一个组件 interface IFiltersInput { onChange?: (e: any) => void; onKeyUp?: (e: any) => void; value?: string; type?: string; id?: string; isInvalid?: boolean; name: string; label: string; } export
interface IFiltersInput {
onChange?: (e: any) => void;
onKeyUp?: (e: any) => void;
value?: string;
type?: string;
id?: string;
isInvalid?: boolean;
name: string;
label: string;
}
export const myInput: FunctionComponent<IFiltersInput> = (props) => {
const btnGroupClasses = {...};
if (props.type === 'number') {
return (
<div className='col-25'>
<label className="label">{props.label}</label>
<input
id={props.id}
className={btnGroupClasses}
onChange={props.onChange}
onKeyUp={props.onKeyUp}
value={props.value}
type="number"
min="0"
/>
</div>
);
}
return (
<div className='col-25'>
<label className="label">{props.label}</label>
<input
type={props.type}
id={props.id}
className={btnGroupClasses}
onChange={props.onChange}
onKeyUp={props.onKeyUp}
value={props.value}
/>
</div>
);
}
接口IFiltersInput{
onChange?:(e:any)=>无效;
onKeyUp?:(e:any)=>无效;
值?:字符串;
类型?:字符串;
id?:字符串;
isInvalid?:布尔值;
名称:字符串;
标签:字符串;
}
导出常量myInput:FunctionComponent=(道具)=>{
常量btnGroupClasses={…};
如果(props.type=='number'){
返回(
{props.label}
);
}
返回(
{props.label}
);
}
然后当我试着上山的时候
describe('myFilter', () => {
...
const component = mount(<myInput name='my-name' label='some-label' inInvalid={false} />);
...
});
description('myFilter',()=>{
...
const component=mount();
...
});
当我得到一个错误时,myInput引用了一个值,但在这里被用作类型ts(2749)
有什么想法吗?我也遇到了同样的问题,并通过将文件扩展名从
.ts
更改为.tsx
解决了这个问题