Problem description
Window.open is used in the code to open a new window, and an error is reported in jest unit test
window.open(url, name, config)
jest not implemented window.open()
Solution:
Directly define the window. Open method in the test file, which should be suitable for all window methods.
window.open = jest.fn()
Note that the mockclear()
method is always called in the test file, because window.Open
is a global object and will always exist during the test.
it('test', () => {
window.open.mockClear()
wrapper.vm.handleOpen()
})
Similar Posts:
- [Solved] Windows Variable packing error: Property ‘XXX‘ does not exist on type ‘Window‘
- Troubleshooting of typescript extended global window error
- The applet reports an error thirdscripterror DateValue is not defined;
- Python uses decorator and reports error typeerror: ‘nonetype’ object is not callable ‘
- window.location And window.open The difference between
- [Solved] IllegalArgumentException: object is not an instance of declaring class
- How to open “file explorer” in Android studio
- The problem of JUnit test report class not found in maven
- Python TypeError: unbound method a() must be called with A instance as first argument (go…
- Access permission problem caused by object. Clone() method