我正在try 为该组件编写单元测试
const HomepageVideos = ({ place, close }) => {
return (
<>
<Button className="mt-2 ms-2 close" onClick={close}>Start Over</Button>
<div className="video text-center">
<video autoPlay muted loop className='mt-3 video' data-testid="video">
{place === 'Dubai-UAE' ?
<source src='dubai.mp4' type="video/mp4" /> :
place === 'Kotor-MONTENEGRO' ?
<source src='kotor.mp4' type="video/mp4" /> :
<source src='tel-aviv.mp4' type="video/mp4" />
}
</video>
<h1>{place}</h1>
<Link to="/flights" state={{ place }}>
<Button className="bg-warning text-dark mt-2">Flights to {place}</Button>
</Link>
</div>
</>
);
}
但是,我编写的任何测试都会返回以下错误消息:
Console.error 错误:未捕获[TypeError:无法解析‘act__nampace.useContext(...)’的属性‘basename’,因为它为空.]
我认为这个错误与在组件HomepageVideos中使用<Link/>
有关.不存在到该组件的特定路径,因为它是本身包括在父组件<Homepage/>
中的另一组件<HomeForm/>
的一部分.我已经将应用程序包装在index.js中的<Router/>
中.该功能运行良好,但我似乎无法编写任何测试.我做错了什么?