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

后端 未结 13 730
轻奢々
轻奢々 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 01:02

    Solution for 2019 from GitHub:

    delete global.window.location;
    global.window = Object.create(window);
    global.window.location = {
      port: '123',
      protocol: 'http:',
      hostname: 'localhost',
    };
    

提交回复
热议问题