Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure comparison of routes is tolerant of an initially undefined query #4341

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export default class Router {
}

urlIsNew (pathname, query) {
return this.pathname !== pathname || !shallowEquals(query, this.query)
return this.pathname !== pathname || !shallowEquals(query || {}, this.query || {})
}

isShallowRoutingPossible (route) {
Expand Down
10 changes: 10 additions & 0 deletions test/unit/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ describe('Router', () => {
expect(Object.keys(pageLoader.loaded)).toEqual(routes)
})
})

describe('.urlIsNew()', () => {
it('should handle undefined starting query parameters', () => {
const pageLoader = new PageLoader()
const router = new Router('/', undefined, '/', { pageLoader })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder in what case this happens 🤔 Could you also add an integration test

Copy link
Author

@baer baer May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens in the case described in #2943.

I'm not sure I see the value in a full on integration test. They tend to be hard to run, somewhat flaky and hard to maintain so I've always favored saving them to smoke test critical paths. This was my experience from working on the Walmart team and with the https://github.com/TestArmada/magellan project anyway. I'm happy to write another unit test if you can think of other ways to cause this behavior.

If you feel strongly that an integration test is the right move here, can you give me some guidance on running the test suite? It nearly crashed my computer and left a bunch of orphaned Chrome processes around last time. Is there a way to do more targeted runs?

// This function will call shallowEqual with the query below and the undefined value set in
// the constructor.
router.urlIsNew('/', { queryVariable: '1' })
})
})
})