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

后端 未结 13 769
轻奢々
轻奢々 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:46

    You can try a helper:

    const setURL = url => global.jsdom.reconfigure({url});
    
    describe('Test current location', () => {
      test('with GET parameter', () => {
        setURL('https://test.com?foo=bar');
        // ...your test here
      });
    });
    

提交回复
热议问题