diff --git a/src/components/do-dont-list/__tests__/__snapshots__/DoDontList.test.tsx.snap b/src/components/do-dont-list/__tests__/__snapshots__/DoDontList.test.tsx.snap index c635ec0e..8dd07a86 100644 --- a/src/components/do-dont-list/__tests__/__snapshots__/DoDontList.test.tsx.snap +++ b/src/components/do-dont-list/__tests__/__snapshots__/DoDontList.test.tsx.snap @@ -13,7 +13,6 @@ exports[`DoDontList matches snapshot: DoDontList-Do 1`] = ` > Do @@ -33,7 +32,6 @@ exports[`DoDontList matches snapshot: DoDontList-Dont 1`] = ` > Don't diff --git a/src/components/table/TableHelpers.ts b/src/components/table/TableHelpers.ts index 208cfc6d..8d791ab7 100644 --- a/src/components/table/TableHelpers.ts +++ b/src/components/table/TableHelpers.ts @@ -6,12 +6,11 @@ export const isTableCell = (child: ReactNode): child is ReactElement => { }; export const getHeadingsFromChildren = (children: ReactNode): string[] => { - return React.Children - .map(children, child => { - if (isTableCell(child)) { - return child.props.children.toString(); - } - return null; - }) - .filter(Boolean); + const headings: string[] = []; + React.Children.map(children, (child) => { + if (isTableCell(child)) { + headings.push(child.props.children.toString()); + } + }); + return headings; }; diff --git a/src/components/warning-callout/__tests__/__snapshots__/WarningCallout.test.tsx.snap b/src/components/warning-callout/__tests__/__snapshots__/WarningCallout.test.tsx.snap index fec85167..ffd32284 100644 --- a/src/components/warning-callout/__tests__/__snapshots__/WarningCallout.test.tsx.snap +++ b/src/components/warning-callout/__tests__/__snapshots__/WarningCallout.test.tsx.snap @@ -10,7 +10,6 @@ exports[`WarningCallout matches snapshot 1`] = ` >

= ({ headingLevel, ...rest }) => { +const HeadingLevel: React.FC = ({ headingLevel='h3', ...rest }) => { switch (headingLevel.toLowerCase()) { case 'h1': return

; @@ -32,10 +32,10 @@ const HeadingLevel: React.FC = ({ headingLevel, ...rest }) => return
; case 'h6': return
; + default: + console.error(`HeadingLevel: Invalid headingLevel prop: ${headingLevel}`); + return

; } }; -HeadingLevel.defaultProps = { - headingLevel: 'h3', -}; export default HeadingLevel; diff --git a/src/util/__tests__/HeadingLevel.test.tsx b/src/util/__tests__/HeadingLevel.test.tsx index c676dee1..11592f4f 100644 --- a/src/util/__tests__/HeadingLevel.test.tsx +++ b/src/util/__tests__/HeadingLevel.test.tsx @@ -43,4 +43,15 @@ describe('HeadingLevel', () => { h6Element.unmount(); H6Element.unmount(); }); + + it("console.warn when headingLevel is invalid", () => { + // eslint-disable-next-line @typescript-eslint/no-empty-function + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + // @ts-expect-error - testing invalid prop + shallow(); + expect(consoleSpy).toHaveBeenCalledTimes(1); + expect(consoleSpy).toHaveBeenCalledWith( + 'HeadingLevel: Invalid headingLevel prop: h7'); + consoleSpy.mockRestore(); + }); }); diff --git a/tsconfig.json b/tsconfig.json index 921295d0..352ba9b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,8 @@ "types": ["react", "jest", "node"], "allowSyntheticDefaultImports": true, "esModuleInterop": true, - "skipLibCheck": true + "skipLibCheck": true, + "strictNullChecks": true }, "include": ["src/**/*"], "exclude": [