Skip to content

Commit

Permalink
[react-router-dom] fix test after migrating flow to ^0.200.0 (#4424)
Browse files Browse the repository at this point in the history
also improve test saying testing `useOutlet` and test `useOutletContext`
  • Loading branch information
iamdey committed Mar 15, 2023
1 parent d934b43 commit 48815e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Expand Up @@ -441,7 +441,7 @@ declare module "react-router-dom" {

declare export function useHistory(): $PropertyType<ContextRouter, 'history'>;
declare export function useLocation(): $PropertyType<ContextRouter, 'location'>;
declare export function useOutletContext<T>(): T;
declare export function useOutletContext<T = any>(): T;
declare export function useParams<Params = $PropertyType<$PropertyType<ContextRouter, 'match'>, 'params'>>(): Params;
declare export function useRouteMatch(path?: MatchPathOptions | string | string[]): $PropertyType<ContextRouter, 'match'>;

Expand Down
Expand Up @@ -14,6 +14,7 @@ import {
useHistory,
useLocation,
useNavigate,
useOutlet,
useOutletContext,
useParams,
useRouteMatch,
Expand Down Expand Up @@ -496,12 +497,34 @@ describe("react-router-dom", () => {
});

it('useOutlet', () => {
useOutlet()

const Component = () => <div>Hi!</div>;

useOutlet<typeof Component>()

// $FlowExpectedError[extra-arg]
useOutlet('')
})

it('useOutletContext', () => {
const [count, setCount] = useOutletContext();
const increment = () => setCount((c) => c + 1);
<button onClick={increment}>{count}</button>;

// $FlowExpectedError[extra-arg]
useOutletContext('');

const t1: number = useOutletContext<number>();

type Tuple = [string, (foo: string) => void];

const [foo, setFoo] = useOutletContext<Tuple>();
(foo: string);
(setFoo: (foo: string) => void);

// $FlowExpectedError[incompatible-type]
const t2: string = useOutletContext<Tuple>();
});

it('useParams', () => {
Expand Down

0 comments on commit 48815e6

Please sign in to comment.