How to test url change with Jest

前端 未结 2 1076
一向
一向 2020-12-17 14:52

I have the following function to test

function tradePage() {
  setTimeout(function() {
    window.location.pathname =          


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 15:35

    I found a working method by declaring in the beginning of the test a global variable:

    global.window = { location: { pathname: null } };
    

    and checked this variable like this:

    expect(global.window.location.pathname).toEqual('/new-url');
    

    That worked fine.

提交回复
热议问题