Skip to content

Commit

Permalink
test Array generic
Browse files Browse the repository at this point in the history
  • Loading branch information
henryqdineen committed Dec 11, 2024
1 parent 5080e22 commit d1fabf3
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions transforms/__tests__/deprecated-react-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function applyTransform(source, options = {}) {
{
path: "test.d.ts",
source: dedent(source),
},
}
);
}

Expand All @@ -21,7 +21,7 @@ test("not modified", () => {
interface Props {
children?: ReactNode;
}
`),
`)
).toMatchInlineSnapshot(`
"import * as React from 'react';
interface Props {
Expand All @@ -37,7 +37,7 @@ test("named import", () => {
interface Props {
children?: ReactChild;
}
`),
`)
).toMatchInlineSnapshot(`
"import { ReactElement } from 'react';
interface Props {
Expand All @@ -53,7 +53,7 @@ test("named type import", () => {
interface Props {
children?: ReactChild;
}
`),
`)
).toMatchInlineSnapshot(`
"import { type ReactElement } from 'react';
interface Props {
Expand All @@ -69,7 +69,7 @@ test("named type import with existing target import", () => {
interface Props {
children?: ReactChild;
}
`),
`)
).toMatchInlineSnapshot(`
"import { ReactElement } from 'react';
interface Props {
Expand All @@ -85,7 +85,7 @@ test("false-negative named renamed import", () => {
interface Props {
children?: MyReactChild;
}
`),
`)
).toMatchInlineSnapshot(`
"import { ReactChild as MyReactChild } from 'react';
interface Props {
Expand All @@ -101,7 +101,7 @@ test("namespace import", () => {
interface Props {
children?: React.ReactChild;
}
`),
`)
).toMatchInlineSnapshot(`
"import * as React from 'react';
interface Props {
Expand All @@ -115,25 +115,41 @@ test("as type parameter", () => {
applyTransform(`
import * as React from 'react';
createAction<React.ReactChild>()
`),
`)
).toMatchInlineSnapshot(`
"import * as React from 'react';
createAction<React.ReactElement | number | string>()"
`);
});

test("array syntax", () => {
test("array type syntax", () => {
expect(
applyTransform(`
import { ReactChild } from 'react';
interface Props {
import { ReactChild } from 'react';
interface Props {
children?: ReactChild[];
}
`),
`)
).toMatchInlineSnapshot(`
"import { ReactElement } from 'react';
interface Props {
children?: (ReactElement | number | string)[];
}"
children?: (ReactElement | number | string)[];
}"
`);
});

test("Array generic", () => {
expect(
applyTransform(`
import { ReactChild } from 'react';
interface Props {
children?: Array<ReactChild>;
}
`)
).toMatchInlineSnapshot(`
"import { ReactElement } from 'react';
interface Props {
children?: Array<ReactElement | number | string>;
}"
`);
});

0 comments on commit d1fabf3

Please sign in to comment.