我正在使用假肢测试法进行测试,以便单位测试我的方法。 其中一个测试项目是,一个州应当把一个接近()的方法点上点击,这反过来又称作浏览器window.close(
):
const close = () => {
console.log( close() called )
window.close()
}
I have a unit test that mocks window.close
but the test is not passing:
expected "spy" to be called once, but got 0 times
我确信,随着我看到奥塞里的话,该构成部分的“接近”方法被称作“。 测试记录中的记录产出。
Here is the test method:
import { test, vi, expect } from "vitest";
import { mount } from "@vue/test-utils";
test( window.close is called when button is clicked , async () => {
const wrapper = mount(MyComponent, {
global: {
plugins: [router]
}
})
const btn = wrapper.find( #exit-button )
await btn.trigger( click )
window.close = vi.fn()
expect(window.close).toHaveBeenCalledOnce()
})