evelynhathaway / jest-location-mock

🗺🧪 Jest hooks for JSDOM location mock
https://npmjs.com/package/jest-location-mock
MIT License
58 stars 5 forks source link

window.history.pushState not working as expected #158

Open saravntbe opened 1 year ago

saravntbe commented 1 year ago

window.history.pushState not working as expected when jest-location-mock is used. clone this repo to reproduce. example (below test fails.)

test('route should be changed', ()=>{
     window.history.pushState({}, 'Test page', '/123')
     expect(window.location.href).toEqual('http://localhost/123')
 })
evelynhathaway commented 1 year ago

Currently, this project only mocks window.location and not the history or navigation APIs. This would be a good future feature 😸

evelynhathaway commented 10 months ago

After digging more into #123, it looks like your issue is also a bug with how JSDOM has limited window.history support, and this mock replaces it.