From 2e64b8ea5741085bdf326701121f35fe358d1e82 Mon Sep 17 00:00:00 2001 From: pelusanchez Date: Thu, 23 Nov 2023 11:51:19 +0100 Subject: [PATCH] Test fixes. --- __tests__/components/GenerateBlocks.test.tsx | 8 +++++--- src/components/GenerateBlocks.tsx | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/__tests__/components/GenerateBlocks.test.tsx b/__tests__/components/GenerateBlocks.test.tsx index ae3ac9d..e13bb2b 100644 --- a/__tests__/components/GenerateBlocks.test.tsx +++ b/__tests__/components/GenerateBlocks.test.tsx @@ -35,7 +35,7 @@ describe('Generate layout from JSON', () => { expect(h1?.id).toBe(`abstract-1`) expect(h1?.innerHTML).toBe(`Here's a Heading`) - const anchor = element.container.querySelector('a') + const anchor = element.container.querySelector('a:not(.anchor)') expect(anchor?.innerHTML).toBe(`link`) expect(anchor).toHaveAttribute('href', 'https://google.com') @@ -69,7 +69,7 @@ describe('Generate layout from JSON', () => { screen.getByText('title text section') screen.getByText('description text example') - const link = document.querySelector('a') + const link = document.querySelector('a:not(.anchor)') as HTMLAnchorElement expect(link?.href).toBe('https://support.ecmwf.int/') expect(link?.target).toBe('_blank') }) @@ -127,7 +127,9 @@ describe('Generate layout from JSON', () => { ]} />, ) - expect(element.container).toBeEmptyDOMElement() + + // Check that we only have an anchor + expect(element.container.childElementCount).toBe(1) }) }) }) diff --git a/src/components/GenerateBlocks.tsx b/src/components/GenerateBlocks.tsx index 4e725c0..d88210f 100644 --- a/src/components/GenerateBlocks.tsx +++ b/src/components/GenerateBlocks.tsx @@ -65,7 +65,9 @@ const GenerateBlocks = ({ <> {blocks && blocks.map((block, i) => { - if (!generateBlockByType[block.type]) return null + if (!generateBlockByType[block.type]) { + return null + } return (