From 45568aede93ce19da1b04439457e5fcbd8285687 Mon Sep 17 00:00:00 2001 From: Matej Jellus Date: Fri, 26 Jul 2024 17:26:42 +0200 Subject: [PATCH] Fix heading test if h1 tag is missing --- src/functions/getHeading.ts | 1 - src/seo/Heading.ts | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/functions/getHeading.ts b/src/functions/getHeading.ts index 1c3d99b..bd03fe2 100644 --- a/src/functions/getHeading.ts +++ b/src/functions/getHeading.ts @@ -1,4 +1,3 @@ -import { URL } from 'url'; import getObject from './getObject'; const getHeading = (result: any): string | string[] => { diff --git a/src/seo/Heading.ts b/src/seo/Heading.ts index b2fbd54..e29748c 100644 --- a/src/seo/Heading.ts +++ b/src/seo/Heading.ts @@ -25,6 +25,14 @@ class Heading extends Test { private checkHeading(title: string | string[]): Array { const results = []; + if (typeof title === 'undefined') { + return [{ + status: 'ERROR', + title: 'H1 tag', + description: 'HTML should contain H1 tag.', + }]; + } + results.push({ status: typeof title !== undefined && title.length > 0 ? 'SUCCESS' : 'WARNING', title: 'H1 tag', @@ -33,13 +41,13 @@ class Heading extends Test { results.push({ status: Array.isArray(title) ? 'ERROR' : 'SUCCESS', title: 'Duplicate H1 tag', - description: `HTML should contain just one title tag.`, + description: `HTML should contain just one H1 tag.`, }); results.push({ status: title.length <= 60 ? 'SUCCESS' : 'WARNING', - title: 'Title length', - description: `Title length should be under 60 characters and it is ${title.length}.`, + title: 'H1 length', + description: `H1 length should be under 60 characters and it is ${title.length}.`, }); return results;