How to test url change with Jest

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

I have the following function to test

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


        
2条回答
  •  北海茫月
    2020-12-17 15:38

    Object.assign(location, { host: "www.newhost.com", pathname: 'file.txt' });
    

    It will update all the location URL object properties (origin, href, hostname, host).

    so the final href property will be https://www.newhost.com/file.txt.

    Do this in a beforeEach block.

    just call console.log(location) to verify the results. Happy coding!

提交回复
热议问题