-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: useActionData now ignores Response
- Loading branch information
1 parent
d07150e
commit d6b3e0c
Showing
6 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { test } from 'bun:test'; | ||
import { ActionFunction, LoaderFunction, redirect } from 'react-router-dom'; | ||
import { useActionData } from '..'; | ||
/** TODO: wait for feedback on issue about act-compat importing deprecated "react-dom/test-utils" */ | ||
import { renderHook } from '@testing-library/react'; | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
test('works with non-promises', () => { | ||
const testAction = (() => { | ||
return { foo: 'bar' }; | ||
}) satisfies ActionFunction; | ||
|
||
const { result } = renderHook(useActionData<typeof testAction>); | ||
expectTypeOf(result.current).toEqualTypeOf<{ foo: string } | undefined>(); | ||
}); | ||
|
||
test('works with promises', () => { | ||
const testAction = (async () => { | ||
return { foo: 'bar' }; | ||
}) satisfies ActionFunction; | ||
|
||
const { result } = renderHook(useActionData<typeof testAction>); | ||
expectTypeOf(result.current).toEqualTypeOf<{ foo: string } | undefined>(); | ||
}); | ||
|
||
test('ignores redirects or responses', () => { | ||
const testAction = (() => { | ||
if (Math.random() > 0.5) { | ||
return redirect('/foo'); | ||
} | ||
if (Math.random() > 0.5) { | ||
return new Response(null, {}); | ||
} | ||
return { foo: 'bar' }; | ||
}) satisfies ActionFunction; | ||
|
||
const { result } = renderHook(useActionData<typeof testAction>); | ||
expectTypeOf(result.current).toEqualTypeOf<{ foo: string } | undefined>(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters