mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
test(frontend): fix local storage setup
This commit is contained in:
1 parent
d143571c2e
commit
0597bf6a37
4 files changed
+30
-1
No files matched your search
@@ -19,6 +19,10 @@ describe('useSidebarCollapsed', () => {
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(global, 'localStorage', {
|
||||
value: window.localStorage,
|
||||
writable: true,
|
||||
})
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useModelStore, modelExists, modelStorePartialize, modelStoreMigrate } f
|
||||
import type { Provider } from '@/api/providers'
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
useModelStore.persist.clearStorage()
|
||||
useModelStore.setState({
|
||||
model: null,
|
||||
agentModels: {},
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
import '@testing-library/jest-dom/vitest'
|
||||
|
||||
const testStorage = (() => {
|
||||
const store = new Map<string, string>()
|
||||
return {
|
||||
getItem: (key: string) => store.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => store.set(key, value),
|
||||
removeItem: (key: string) => store.delete(key),
|
||||
clear: () => store.clear(),
|
||||
}
|
||||
})()
|
||||
|
||||
Object.defineProperty(window, 'localStorage', {
|
||||
value: testStorage,
|
||||
writable: true,
|
||||
})
|
||||
|
||||
Object.defineProperty(globalThis, 'localStorage', {
|
||||
value: window.localStorage,
|
||||
writable: true,
|
||||
})
|
||||
|
||||
global.ResizeObserver = class ResizeObserver {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
|
||||
@@ -6,6 +6,11 @@ export default defineConfig({
|
||||
plugins: [react()],
|
||||
test: {
|
||||
environment: "jsdom",
|
||||
environmentOptions: {
|
||||
jsdom: {
|
||||
url: "http://localhost",
|
||||
},
|
||||
},
|
||||
globals: true,
|
||||
env: {
|
||||
NODE_ENV: "test",
|
||||
|
||||
Reference in new issue
Block a user