Skip to content

Commit

Permalink
tests: add tests for local-storage api
Browse files Browse the repository at this point in the history
  • Loading branch information
FoHoOV committed Nov 9, 2024
1 parent 915ef98 commit 3dc4c5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions frontend/src/lib/utils/storage-types/local-storage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect, test, vi, describe, beforeEach } from 'vitest';
import { LocalStorage } from './local-storage';
import * as environment from '$app/environment';

describe.each([
{ isBrowser: true, expectedLocalValue: 'value' },
{ isBrowser: false, expectedLocalValue: 'value' }
])('LocalStorage in environment context', ({ isBrowser, expectedLocalValue }) => {
beforeEach(() => {
vi.spyOn(environment, 'browser', 'get').mockReturnValue(isBrowser);
});

test(`${isBrowser ? 'browser' : 'server'}: correctly sets and retrieves items`, () => {
const storage = new LocalStorage();
storage.setItem('test', expectedLocalValue);
expect(storage.getItem('test')).toEqual(expectedLocalValue);
});
});
1 change: 1 addition & 0 deletions frontend/src/lib/utils/storage-types/local-storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { browser } from '$app/environment';
import * as environment from '$app/environment';

export class LocalStorage {
#serverSideItems = new Map<string, string>();
Expand Down

0 comments on commit 3dc4c5c

Please sign in to comment.