且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Jest 测试 url 更改

更新时间:2023-01-15 13:39: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');

效果很好.