From fcddd07514ace51bdfc1a277276d31e1b56b53dd Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Thu, 6 Jun 2024 13:53:48 -0400 Subject: [PATCH] fix(react): prevent generating empty props since setting strict in tsconfig is not compatible with it --- .../next/src/generators/page/page.spec.ts | 2 -- .../__snapshots__/component-test.spec.ts.snap | 33 ++++--------------- .../component/files/__fileName__.tsx__tmpl__ | 10 ++---- ...press-component-configuration.spec.ts.snap | 20 +++-------- 4 files changed, 13 insertions(+), 52 deletions(-) diff --git a/packages/next/src/generators/page/page.spec.ts b/packages/next/src/generators/page/page.spec.ts index 4eb29d5b2a465..49b602240e6ac 100644 --- a/packages/next/src/generators/page/page.spec.ts +++ b/packages/next/src/generators/page/page.spec.ts @@ -56,7 +56,6 @@ describe('component', () => { const content = tree .read('my-app/pages/posts/[dynamic]/index.tsx') .toString(); - expect(content).toMatch(/DynamicProps/); }); }); @@ -97,7 +96,6 @@ describe('component', () => { const content = tree .read(`${appRouterProjectName}/app/posts/[dynamic]/page.tsx`) .toString(); - expect(content).toMatch(/DynamicProps/); }); }); }); diff --git a/packages/react/src/generators/component-test/__snapshots__/component-test.spec.ts.snap b/packages/react/src/generators/component-test/__snapshots__/component-test.spec.ts.snap index 9f5cea3710a29..05450ac5e33fb 100644 --- a/packages/react/src/generators/component-test/__snapshots__/component-test.spec.ts.snap +++ b/packages/react/src/generators/component-test/__snapshots__/component-test.spec.ts.snap @@ -64,19 +64,12 @@ describe(AnotherCmp2.name, () => { exports[`componentTestGenerator multiple components per file should handle no props 1`] = ` "import * as React from 'react' -import SomeLib, { SomeLibProps, AnotherCmp } from './some-lib' +import SomeLib, { AnotherCmp } from './some-lib' describe(SomeLib.name, () => { - let props: SomeLibProps; - - beforeEach(() => { - props = { - } - }) - it('renders', () => { - cy.mount() + cy.mount() }) }) @@ -91,19 +84,12 @@ describe(AnotherCmp.name, () => { exports[`componentTestGenerator multiple components per file should handle props 1`] = ` "import * as React from 'react' -import SomeLib, { SomeLibProps, AnotherCmpProps, AnotherCmp } from './some-lib' +import SomeLib, { AnotherCmpProps, AnotherCmp } from './some-lib' describe(SomeLib.name, () => { - let props: SomeLibProps; - - beforeEach(() => { - props = { - } - }) - it('renders', () => { - cy.mount() + cy.mount() }) }) @@ -179,19 +165,12 @@ describe(AnotherCmp.name, () => { exports[`componentTestGenerator single component per file should handle no props 1`] = ` "import * as React from 'react' -import SomeLib, { SomeLibProps } from './some-lib' +import SomeLib from './some-lib' describe(SomeLib.name, () => { - let props: SomeLibProps; - - beforeEach(() => { - props = { - } - }) - it('renders', () => { - cy.mount() + cy.mount() }) }) diff --git a/packages/react/src/generators/component/files/__fileName__.tsx__tmpl__ b/packages/react/src/generators/component/files/__fileName__.tsx__tmpl__ index cbe8661ac0361..789f2d8d10b00 100644 --- a/packages/react/src/generators/component/files/__fileName__.tsx__tmpl__ +++ b/packages/react/src/generators/component/files/__fileName__.tsx__tmpl__ @@ -23,10 +23,6 @@ import { Route, Link } from 'react-router-dom'; var extras = ''; } %> -/* eslint-disable-next-line */ -export interface <%= className %>Props { -} - <% if (styledModule && styledModule !== 'styled-jsx') { %> const Styled<%= className %> = styled.div` color: pink; @@ -34,7 +30,7 @@ const Styled<%= className %> = styled.div` <% }%> <% if(!isNextPage) { %> <% if (classComponent) { %> - export class <%= className %> extends Component<<%= className %>Props> { + export class <%= className %> extends Component<{}> { override render() { return ( <<%= wrapper %><%- extras %>> @@ -51,7 +47,7 @@ const Styled<%= className %> = styled.div` } } <% } else { %> - export function <%= className %>(props: <%= className %>Props) { + export function <%= className %>() { return ( <<%= wrapper %><%- extras %>> <% if (styledModule === 'styled-jsx') { %><% } %> @@ -69,7 +65,7 @@ const Styled<%= className %> = styled.div` export default <%= className %>; <% } else { %> - export default function <%= className %>(props: <%= className %>Props) { + export default function <%= className %>() { return ( <<%= wrapper %><%- extras %>> <% if (styledModule === 'styled-jsx') { %><% } %> diff --git a/packages/react/src/generators/cypress-component-configuration/__snapshots__/cypress-component-configuration.spec.ts.snap b/packages/react/src/generators/cypress-component-configuration/__snapshots__/cypress-component-configuration.spec.ts.snap index 7ccbd6184d69a..7fde93b56c680 100644 --- a/packages/react/src/generators/cypress-component-configuration/__snapshots__/cypress-component-configuration.spec.ts.snap +++ b/packages/react/src/generators/cypress-component-configuration/__snapshots__/cypress-component-configuration.spec.ts.snap @@ -66,17 +66,11 @@ describe(AnotherCmp.name, () => { exports[`React:CypressComponentTestConfiguration should generate tests for existing tsx components 1`] = ` "import * as React from 'react'; -import SomeLib, { SomeLibProps } from './some-lib'; +import SomeLib from './some-lib'; describe(SomeLib.name, () => { - let props: SomeLibProps; - - beforeEach(() => { - props = {}; - }); - it('renders', () => { - cy.mount(); + cy.mount(); }); }); " @@ -84,17 +78,11 @@ describe(SomeLib.name, () => { exports[`React:CypressComponentTestConfiguration should generate tests for existing tsx components 2`] = ` "import * as React from 'react'; -import AnotherCmp, { AnotherCmpProps } from './another-cmp'; +import AnotherCmp from './another-cmp'; describe(AnotherCmp.name, () => { - let props: AnotherCmpProps; - - beforeEach(() => { - props = {}; - }); - it('renders', () => { - cy.mount(); + cy.mount(); }); }); "