Skip to content

Commit 7e541c9

Browse files
committed
tidy up tests
1 parent ccc824b commit 7e541c9

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

packages/start-client-core/src/tests/createServerFn.test-d.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import type {
88
TsrSerializable,
99
Validator,
1010
} from '@tanstack/router-core'
11-
import type { ConstrainValidator } from '../createServerFn'
11+
import type {
12+
ConstrainValidator,
13+
ServerFnReturnType,
14+
} from '../createServerFn'
1215

1316
test('createServerFn method with autocomplete', () => {
1417
createServerFn().handler((options) => {
@@ -380,19 +383,24 @@ describe('response', () => {
380383
expectTypeOf(fn()).toEqualTypeOf<Promise<Response>>()
381384
})
382385

383-
test(`client receives union when handler may return Response or data`, () => {
386+
test(`client receives union when handler may return Response or string`, () => {
384387
const fn = createServerFn().handler(() => {
385-
return Math.random() > 0.5
386-
? new Response('Hello World')
387-
: ({ message: 'Hello World' } as const)
388+
const result: Response | 'Hello World' =
389+
Math.random() > 0.5 ? new Response('Hello World') : 'Hello World'
390+
391+
return result
388392
})
389393

390-
expectTypeOf(fn()).toEqualTypeOf<
391-
Promise<Response | { readonly message: 'Hello World' }>
392-
>()
394+
expectTypeOf(fn()).toEqualTypeOf<Promise<Response | 'Hello World'>>()
393395
})
394396
})
395397

398+
test('ServerFnReturnType distributes Response union', () => {
399+
expectTypeOf<
400+
ServerFnReturnType<Register, Response | 'Hello World'>
401+
>().toEqualTypeOf<Response | 'Hello World'>()
402+
})
403+
396404
test('createServerFn can be used as a mutation function', () => {
397405
const serverFn = createServerFn()
398406
.inputValidator((data: number) => data)

0 commit comments

Comments
 (0)