remix-run / history

Manage session history with JavaScript
MIT License
8.29k stars 960 forks source link

Test improvement: observe window.location #918

Open thejohnhoffer opened 2 years ago

thejohnhoffer commented 2 years ago

Expected behavior

Tests should ensure window.location is correctly modified.

Actual behavior

Test sequences only test against history.location

Details

For HashHistory, "window.location" and "history" should be related as follows:

const historyHref = createPath(history.location);
const windowHref = window.location.hash.substr(1);
expect(historyHref).toEqual(windowHref)

All of the tests in the "TestSequences" folder only test against history.location, but there is currently "no guarantee" that the location is actually reflected in the window.location.

In my PR to solve Issue #912, I noticed there is currently no test of the relationship between the two location states. That PR therefore happens to include a general fix for this issue. If PR #911 is ultimately rejected, this issue could be solved with a new PR just with this:

afterEach(() => { 
  const historyHref = createPath(history.location);
  const windowHref = window.location.hash.substr(1);
  expect(historyHref).toEqual(windowHref);
})

added to packages/history/__tests__/hash-test.js