Skip to content

Commit 8cd3643

Browse files
committed
Use test macro
1 parent 5145615 commit 8cd3643

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"zod": "^3.0.0"
7171
},
7272
"devDependencies": {
73-
"@seamapi/url-search-params-serializer": "^2.0.0-beta.0",
73+
"@seamapi/url-search-params-serializer": "^2.0.0-beta.2",
7474
"@types/node": "^20.8.10",
7575
"ava": "^6.0.1",
7676
"c8": "^10.1.2",

src/lib/parse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ZodTypeAny } from 'zod'
1+
import type { ZodSchema } from 'zod'
22

33
import {
44
type ParamSchema,
@@ -9,7 +9,7 @@ import { isZodObject } from './zod.js'
99

1010
export const parseUrlSearchParams = (
1111
query: URLSearchParams | string,
12-
schema: ZodTypeAny,
12+
schema: ZodSchema,
1313
): Record<string, unknown> => {
1414
const searchParams =
1515
typeof query === 'string' ? new URLSearchParams(query) : query

test/parse.test.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
import { serializeUrlSearchParams } from '@seamapi/url-search-params-serializer'
1+
import {
2+
type Params,
3+
serializeUrlSearchParams,
4+
} from '@seamapi/url-search-params-serializer'
25
import test from 'ava'
3-
import { z } from 'zod'
6+
import { z, type ZodSchema } from 'zod'
47

58
import { parseUrlSearchParams } from '@seamapi/url-search-params-parser'
69

7-
test('parses empty params', (t) => {
8-
const schema = z.object({ foo: z.string() })
9-
const input = {}
10-
t.deepEqual(parseUrlSearchParams(serializeUrlSearchParams(input), schema), {
11-
foo: undefined,
12-
})
10+
const parses = test.macro((t, input: Params, schema: ZodSchema) => {
11+
t.deepEqual(
12+
parseUrlSearchParams(serializeUrlSearchParams(input), schema),
13+
input,
14+
)
1315
})
1416

15-
test('parses nested params', (t) => {
16-
const schema = z.object({
17-
foo: z.string(),
18-
bar: z.object({ baz: z.string() }),
19-
})
20-
const input = { foo: 'a', bar: { baz: 'b' } }
21-
t.deepEqual(parseUrlSearchParams(serializeUrlSearchParams(input), schema), {
17+
test('parses empty params', parses, {
18+
foo: undefined,
19+
}, z.object({ foo: z.string() }))
20+
21+
test(
22+
'parses nested params',
23+
parses,
24+
{
2225
foo: 'a',
2326
bar: { baz: 'b' },
24-
})
25-
})
27+
},
28+
z.object({
29+
foo: z.string(),
30+
bar: z.object({ baz: z.string() }),
31+
}),
32+
)

0 commit comments

Comments
 (0)