如何解决单击触发时未调用带有nuxt-link的Nav项目
我有导航组件,该组件使用nuxt-link
列出了几个链接。我想测试我的导航组件是否调用了正确的路径。我有几个问题/问题:
- 但是在Jest&Vue Test Utils中使用模拟路由器进行测试时,单击不会触发路由更改
错误消息:
● Nav Item behaviors › send to overview page when Employees menu is clicked
expect(jest.fn()).toHaveBeenCalledWith(...expected)
Expected: "/employees"
Number of calls: 0
102 | await navItem.trigger('click')
103 |
> 104 | expect(router.push).toHaveBeenCalledWith('/employees')
| ^
105 | })
106 | })
- 我想断言链接到
a
的{{1}}元素以拥有/employees
类。但是不知何故,它甚至没有一个,甚至通过最初强制active
成为route
路径来实现。
下面是我的测试代码:
/employees
我的导航栏组件在下面:
import { shallowMount,RouterLinkStub,mount } from '@vue/test-utils'
import Navbar from './index.vue'
import localVue from '@/test/local_vue'
const router = {
push: jest.fn(),}
mockAuth.loggedIn = true
let setupWrapper = () => {
return mount(Navbar,{
localVue,global: {
mocks: {
$router: router,},mocks: {
$auth: mockAuth,stubs: {
FlexLogo: FlexLogo,UserProfile: UserProfile,NuxtLink: RouterLinkStub,RouterLink: RouterLinkStub,});
};
describe('Nav Item behaviors',() => {
beforeEach(() => {
wrapper = setupWrapper()
})
test('send to overview page when Employees menu is clicked',async () => {
let navItem = wrapper.findAllComponents(RouterLinkStub).at(2)
await navItem.trigger('click')
expect(router.push).toHaveBeenCalledWith('/employees')
})
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。