From b8cd0fee76415e71513f757fc0cc82f6fb3df5e9 Mon Sep 17 00:00:00 2001 From: Benoit Tremblay Date: Sat, 30 Dec 2023 10:35:44 -0500 Subject: [PATCH] Fix global undefined error in browser (#433) --- packages/universal-cookie/src/utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/universal-cookie/src/utils.ts b/packages/universal-cookie/src/utils.ts index 588ecb9..1d12a1e 100644 --- a/packages/universal-cookie/src/utils.ts +++ b/packages/universal-cookie/src/utils.ts @@ -2,7 +2,11 @@ import * as cookie from 'cookie'; import { Cookie, CookieGetOptions } from './types'; export function hasDocumentCookie() { - const testingValue = (global as any).TEST_HAS_DOCUMENT_COOKIE; + const testingValue = + typeof global === 'undefined' + ? undefined + : (global as any).TEST_HAS_DOCUMENT_COOKIE; + if (typeof testingValue === 'boolean') { return testingValue; }