我需要帮助,我想通过搜索在图形渲染后应该出现的单词来测试图形是否正在渲染给我,但得到了一个错误。我正在尝试用JEST编写测试,下面是一个绘制图形的函数
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>
</>
);
}下面是我的测试
describe('<Graph /> ', () => {
it('should be redner', () => {
render(<Graph data={[65]} labels={['monday']} ></Graph>);
expect(screen.getByText('monday')).toBeTruthy;
});
})还有我的bug
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 | })我听不懂,请帮帮忙。
发布于 2020-10-11 03:36:13
在可用上下文有限的情况下,我只能猜测问题所在。但是似乎Graph对于jest来说是未知的。请检查是否已在测试文件或测试帮助器中正确导入了Graph组件。
有关jest和react的更多信息:https://jestjs.io/docs/en/tutorial-react
https://stackoverflow.com/questions/64296927
复制相似问题