From 6c7d0e2e0e740f5aa07dde1f0f00cd839bbd4f0c Mon Sep 17 00:00:00 2001 From: Mark Gibbons Date: Thu, 29 Aug 2024 10:39:51 +1000 Subject: [PATCH] Add unit tests for expected nextjs href behaviour --- .../src/components/Link.test.tsx | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/sitecore-jss-nextjs/src/components/Link.test.tsx b/packages/sitecore-jss-nextjs/src/components/Link.test.tsx index c741feb38b..774143e43b 100644 --- a/packages/sitecore-jss-nextjs/src/components/Link.test.tsx +++ b/packages/sitecore-jss-nextjs/src/components/Link.test.tsx @@ -351,14 +351,35 @@ describe('', () => { it('should render nothing with missing field', () => { const field = (null as unknown) as LinkField; - const rendered = mount().children(); - expect(rendered).to.have.length(0); + const rendered = mount(); + expect(rendered.html()).to.equal(null); }); it('should render nothing with missing field', () => { const field = {}; - const rendered = mount().children(); - expect(rendered).to.have.length(0); + const rendered = mount(); + expect(rendered.html()).to.equal(null); + }); + + it('should render nothing when field is present and href is not present', () => { + const field = { + value: { + text: 'ipsum', + }, + }; + const rendered = mount(); + expect(rendered.html()).to.equal(''); + }); + + it('should render when field is present and href is present', () => { + const field = { + value: { + text: 'ipsum', + href: '/lorem', + }, + }; + const rendered = mount(); + expect(rendered.html()).to.equal('ipsum'); }); describe('editMode metadata', () => {