Last active
May 19, 2021 09:11
-
-
Save karpolan/d1d5dd7b061659398d456c2ff7730a91 to your computer and use it in GitHub Desktop.
TypeScript - testing <head> meta tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getMetaTagContent(metaTagName: string): string | null { | |
const metaTags: HTMLCollectionOf<HTMLMetaElement> = document.getElementsByTagName('meta'); | |
const nameToFind = metaTagName.toLowerCase(); | |
for (const current of metaTags) { | |
if (current.getAttribute('name')?.toLowerCase() === nameToFind) { | |
return current.getAttribute('content'); | |
} | |
} | |
return ''; | |
} | |
/* | |
How to use: | |
// Check Real DOM elements | |
waitFor(() => { | |
expect(document.title).toEqual('title...'); | |
expect(getMetaTagContent('description')).toEqual('description...'); | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment