Skip to content

Conversation

@madeindjs
Copy link
Collaborator

It's possible to use URLSearchParams instead of complex Regex. As it's a very testable part of the code, it was a good opportunity to introduce Vitest and cover it.

This improvement made me realise that a bug was present, and we didn't serialize the params when converting back the object to hash (.key = length was not called).

@madeindjs madeindjs self-assigned this Nov 27, 2024
hash += `${encodeURIComponent(pageKey)}`;
}

if (routeVars.keys.length > 0) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a bug, since we need to use .size

> const map = new Map()
undefined
> map.keys.length
0
> map.set('a','b')
Map(1) { 'a' => 'b' }
> map.keys.length
0
> map.size
1

@madeindjs madeindjs changed the title chore(ui): improve hash parsing + test - WF-72 chore(ui): improve hash parsing + setup unit test - WF-72 Nov 28, 2024
@madeindjs madeindjs marked this pull request as ready for review November 28, 2024 08:31
@madeindjs madeindjs marked this pull request as draft November 28, 2024 08:55
It's possible to use `URLSearchParams` instead of complex Regex. As
it'sa very testable part of the code, it was a good opportunity to
introduceVitest and cover it.This improvement made me realise that a bug
was present, and we didn'tserialize the params when converting back the
object to hash (`.key =length` was not called).
@madeindjs madeindjs marked this pull request as ready for review November 28, 2024 09:17
@ramedina86 ramedina86 merged commit 66eaa60 into writer:dev Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants