Jestjs 如何测试图表以查看其渲染是否正确
我需要帮助,我想通过搜索图形渲染后应该出现的单词来测试图形是否呈现给我,但它得到了一个错误。 我在开玩笑地写测试 下面是一个绘制图表的函数Jestjs 如何测试图表以查看其渲染是否正确,jestjs,Jestjs,我需要帮助,我想通过搜索图形渲染后应该出现的单词来测试图形是否呈现给我,但它得到了一个错误。 我在开玩笑地写测试 下面是一个绘制图表的函数 export interface CharProps { data:Array<any>, labels:Array<any> } export const Graph: React.FC<CharProps> = ({labels,data}) => { const [chartDat
export interface CharProps {
data:Array<any>,
labels:Array<any>
}
export const Graph: React.FC<CharProps> = ({labels,data}) => {
const [chartData, setChartData]= useState({})
const chart = ()=>{
setChartData({
labels:labels,
datasets:[
{
label: 'Annual revenue',
fill: false,
}
]
})
}
useEffect(()=>{
chart()
},[])
return (
<>
<div className={chartBackground}>
<Line data={chartData} options={{responsive:true}}/>
</div>
</>
);
}
导出接口CharProps{
数据:数组,
标签:数组
}
导出常量图:React.FC=({labels,data})=>{
常量[chartData,setChartData]=useState({})
常数图=()=>{
setChartData({
标签:标签,
数据集:[
{
标签:“年收入”,
填充:假,
}
]
})
}
useffect(()=>{
图表()
},[])
返回(
);
}
下面是我的测试
describe('<Graph /> ', () => {
it('should be redner', () => {
render(<Graph data={[65]} labels={['monday']} ></Graph>);
expect(screen.getByText('monday')).toBeTruthy;
});
})
描述(“”,()=>{
它('应该是redner',()=>{
render();
expect(screen.getByText('monday')).toBeTruthy;
});
})
还有我的虫子
TypeError: Cannot set property '_options' of undefined
8 | describe('<Graph /> ', () => {
9 | it('should be redner', () => {
> 10 | render(<Graph data={[65]} labels={['monday']} ></Graph>);
| ^
11 | expect(screen.getByText('monday')).toBeTruthy;
12 | });
13 | })
TypeError:无法设置未定义的属性“\u options”
8 |描述(“”,()=>{
9 |它('应该是红色的',()=>{
>10 | render();
| ^
11 | expect(screen.getByText('monday')).toBeTruthy;
12 | });
13 | })
我无法理解,请帮助。由于可用的上下文有限,我只能猜测问题出在哪里。但这张图似乎不知道该怎么开玩笑。请检查是否已在测试文件或测试助手中正确导入图形组件 有关jest和react的更多信息: