Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 2e64b8e

Browse files
committed
Test fixes.
1 parent fd7b80f commit 2e64b8e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

__tests__/components/GenerateBlocks.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Generate layout from JSON', () => {
3535
expect(h1?.id).toBe(`abstract-1`)
3636
expect(h1?.innerHTML).toBe(`Here's a Heading`)
3737

38-
const anchor = element.container.querySelector('a')
38+
const anchor = element.container.querySelector('a:not(.anchor)')
3939
expect(anchor?.innerHTML).toBe(`link`)
4040
expect(anchor).toHaveAttribute('href', 'https://google.com')
4141

@@ -69,7 +69,7 @@ describe('Generate layout from JSON', () => {
6969

7070
screen.getByText('title text section')
7171
screen.getByText('description text example')
72-
const link = document.querySelector('a')
72+
const link = document.querySelector('a:not(.anchor)') as HTMLAnchorElement
7373
expect(link?.href).toBe('https://support.ecmwf.int/')
7474
expect(link?.target).toBe('_blank')
7575
})
@@ -127,7 +127,9 @@ describe('Generate layout from JSON', () => {
127127
]}
128128
/>,
129129
)
130-
expect(element.container).toBeEmptyDOMElement()
130+
131+
// Check that we only have an anchor
132+
expect(element.container.childElementCount).toBe(1)
131133
})
132134
})
133135
})

src/components/GenerateBlocks.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ const GenerateBlocks = ({
6565
<>
6666
{blocks &&
6767
blocks.map((block, i) => {
68-
if (!generateBlockByType[block.type]) return null
68+
if (!generateBlockByType[block.type]) {
69+
return null
70+
}
6971
return (
7072
<React.Fragment key={`${i}_${block.id}`}>
7173
<Anchor className="anchor" id={block.id} />

0 commit comments

Comments
 (0)