From d8904f768ae5aad951197e736e62152e460101fd Mon Sep 17 00:00:00 2001 From: Dan Reeves Date: Tue, 7 Jun 2022 16:28:17 +0100 Subject: [PATCH 1/4] Example of how types allow incorrect usage --- test/trans.render.object.spec.js | 29 +++++++++++++++++++++++++++++ test/typescript/Trans.test.tsx | 23 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/test/trans.render.object.spec.js b/test/trans.render.object.spec.js index d0d8d207..5c437278 100644 --- a/test/trans.render.object.spec.js +++ b/test/trans.render.object.spec.js @@ -242,3 +242,32 @@ describe('trans using no children but components (object) - interpolated compone `); }); }); + +describe('trans using no children but components (object) - ReactNodes that error', () => { + const Button = ({ children }) => ; + // Suppress console.errors in these tests + let consoleErrorFn; + beforeAll(() => { + consoleErrorFn = jest.spyOn(console, 'error').mockImplementation(() => jest.fn()); + }); + afterAll(() => { + consoleErrorFn.restoreMocks(); + }); + it('should throw if you use some valid ReactNodes', () => { + expect(() => + render(), + ).toThrow(); + + expect(() => + render(), + ).toThrow(); + + expect(() => + render(), + ).toThrow(); + + expect(() => + render(), + ).toThrow(); + }); +}); diff --git a/test/typescript/Trans.test.tsx b/test/typescript/Trans.test.tsx index da1ea1a2..0197b0c7 100644 --- a/test/typescript/Trans.test.tsx +++ b/test/typescript/Trans.test.tsx @@ -26,6 +26,29 @@ function objectComponents() { return }} defaults="Hello " />; } +function MyComponent(): React.ReactElement { + return <>world; +} + +function objectCustomComponents() { + return }} defaults="Hello " />; +} + +function objectCustomComponentsShouldError() { + return ( + + ); +} + function constObjectComponents() { const constObject = { Btn: ; - // Suppress console.errors in these tests - let consoleErrorFn; - beforeAll(() => { - consoleErrorFn = jest.spyOn(console, 'error').mockImplementation(() => jest.fn()); - }); - afterAll(() => { - consoleErrorFn.restoreMocks(); - }); - it('should throw if you use some valid ReactNodes', () => { - expect(() => - render(), - ).toThrow(); - - expect(() => - render(), - ).toThrow(); - - expect(() => - render(), - ).toThrow(); - - expect(() => - render(), - ).toThrow(); - }); -});