提问人:Udders 提问时间:11/16/2023 更新时间:11/16/2023 访问量:21
vitest 路由器链路存根不显示文本
vitest router-link stub not display the text
问:
我有一个vitest来测试一个按钮组件,测试看起来像这样,
it('renders a router-link when href prop is provided', () => {
const wrapper = shallowMount(Button, {
props: {
buttonText: 'Go to Home',
href: '/home',
},
stubs: {
RouterLink: RouterLinkStub
}
});
//expect(wrapper).toMatchSnapshot()
// Check that the component is rendered as a router-link
expect(wrapper.findComponent(RouterLink).exists()).toBe(true);
// Check that the router-link has the correct 'to' prop
expect(wrapper.findComponent(RouterLink).props().to).toBe('/home');
// Check that the router-link text is correct
const routerLinkComponent = wrapper.findComponent(RouterLink)
console.log(routerLinkComponent.html().toContain);
});
回报,console.log
<router-link-stub to="/home" replace="false" custom="false" ariacurrentvalue="page" class="bg-blue-600 px-4 py-2 leading-5 text-center text-white text-xl rounded block"></router-link-stub>
我希望有文字“回家”,但事实并非如此。当实际使用组件时,内部文本确实呈现给用户?<router-link-stub>
答: 暂无答案
评论