test: add test to ensure that node is defined (#419)

This commit is contained in:
Nolan Lawson 2024-04-12 19:05:34 -07:00 committed by GitHub
parent 3d84cf384e
commit 028f4dc8ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -1,7 +1,13 @@
// get the width of the text inside of a DOM node, via https://stackoverflow.com/a/59525891/680742
export function calculateTextWidth (node) {
// skip running this in jest/vitest because we don't need to check for emoji support in that environment
/* istanbul ignore else */
if (import.meta.env.MODE === 'test') {
// sanity check to make sure the node is defined properly
/* istanbul ignore if */
if (!node) {
throw new Error('node should not be undefined/null')
}
return 1
} else {
const range = document.createRange()