How to mock [removed].href with Jest + Vuejs?

后端 未结 13 753
轻奢々
轻奢々 2020-12-24 00:32

Currently, I am implementing unit test for my project and there is a file that contained window.location.href.

I want to mock this to test and here is m

13条回答
  •  清歌不尽
    2020-12-24 00:52

    I have resolved this issue by adding writable: true and move it to beforeEach

    Here is my sample code:

    global.window = Object.create(window);
    const url = "http://dummy.com";
    Object.defineProperty(window, "location", {
        value: {
           href: url
        },
        writable: true
    });
    

提交回复
热议问题