From 2dc7fb2c19c0e63a7858d5b11f647a33e89a98a7 Mon Sep 17 00:00:00 2001 From: adamjmcgrath Date: Thu, 17 Sep 2020 15:33:33 +0200 Subject: [PATCH] Fix SSR --- __tests__/cache.test.ts | 1 + __tests__/transaction-manager.test.ts | 1 + jest.config.js | 3 +-- src/storage.ts | 3 +++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts index 05805b10c..0f38f89e7 100644 --- a/__tests__/cache.test.ts +++ b/__tests__/cache.test.ts @@ -1,3 +1,4 @@ +import 'jest-localstorage-mock'; import { InMemoryCache, LocalStorageCache, ICache } from '../src/cache'; const nowSeconds = () => Math.floor(Date.now() / 1000); diff --git a/__tests__/transaction-manager.test.ts b/__tests__/transaction-manager.test.ts index 251222fe2..f2b99aa11 100644 --- a/__tests__/transaction-manager.test.ts +++ b/__tests__/transaction-manager.test.ts @@ -1,3 +1,4 @@ +import 'jest-localstorage-mock'; import TransactionManager from '../src/transaction-manager'; import { SessionStorage } from '../src/storage'; import { mocked } from 'ts-jest/utils'; diff --git a/jest.config.js b/jest.config.js index d335eea41..dcf446055 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,6 +12,5 @@ module.exports = { ['jest-junit', { outputDirectory: 'test-results/jest' }] ], coverageReporters: ['lcov', 'text', 'text-summary'], - preset: 'ts-jest', - setupFiles: ['jest-localstorage-mock'] + preset: 'ts-jest' }; diff --git a/src/storage.ts b/src/storage.ts index 95d79df17..76982317e 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -85,6 +85,9 @@ export const CookieStorageWithLegacySameSite = { */ export const SessionStorage = { get(key: string) { + if (typeof sessionStorage === 'undefined') { + return; + } const value = sessionStorage.getItem(key); if (typeof value === 'undefined') { return;