Skip to content

Commit ec596ee

Browse files
authored
Merge pull request #30 from hosmelq/check-possible-undefined
Check possible undefined
2 parents 747731a + 3d8cda5 commit ec596ee

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

resources/js/wayfinder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export const queryParams = (options?: {
6060
});
6161

6262
for (const subKey in query[key]) {
63-
params.set(`${key}[${subKey}]`, getValue(query[key][subKey]));
63+
if (query[key][subKey] !== undefined) {
64+
params.set(`${key}[${subKey}]`, getValue(query[key][subKey]));
65+
}
6466
}
6567
} else {
6668
params.set(key, getValue(query[key]));

tests/QueryParams.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,29 @@ it("can merge with the form method", () => {
168168
method: "get",
169169
});
170170
});
171+
172+
it("handles nested objects with undefined keys", () => {
173+
window.location.search = "?parent=og";
174+
175+
const query = (): {
176+
good: string;
177+
} => {
178+
const obj = {
179+
good: 'value',
180+
bad: undefined,
181+
}
182+
183+
return obj
184+
}
185+
186+
expect(
187+
index.form.head({
188+
mergeQuery: {
189+
parent: query(),
190+
},
191+
}),
192+
).toEqual({
193+
action: "/posts?parent=og&_method=HEAD&parent%5Bgood%5D=value",
194+
method: "get",
195+
});
196+
});

0 commit comments

Comments
 (0)