Skip to content

Commit 89c89bc

Browse files
committed
fix: unit test for use-settings fixes
1 parent e3f7315 commit 89c89bc

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

test/nuxt/composables/use-settings.spec.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
22

33
describe('useSettings - keyboardShortcuts', () => {
44
beforeEach(() => {
55
localStorage.clear()
6+
vi.resetModules()
67
})
78

89
afterEach(() => {
910
// Reset the singleton so the next test gets a fresh instance
1011
localStorage.clear()
12+
vi.resetModules()
1113
})
1214

1315
describe('default value', () => {
14-
it('should default keyboardShortcuts to true', () => {
16+
it('should default keyboardShortcuts to true', async () => {
17+
const { useSettings } = await import('../../../app/composables/useSettings')
1518
const { settings } = useSettings()
1619
expect(settings.value.keyboardShortcuts).toBe(true)
1720
})
1821
})
1922

2023
describe('useKeyboardShortcuts composable', () => {
21-
it('should return true by default', () => {
24+
it('should return true by default', async () => {
25+
const { useKeyboardShortcuts } = await import('../../../app/composables/useSettings')
2226
const enabled = useKeyboardShortcuts()
2327
expect(enabled.value).toBe(true)
2428
})
2529

26-
it('should reflect changes made via settings', () => {
30+
it('should reflect changes made via settings', async () => {
31+
const { useSettings } = await import('../../../app/composables/useSettings')
2732
const { settings } = useSettings()
2833
const enabled = useKeyboardShortcuts()
2934

@@ -34,7 +39,9 @@ describe('useSettings - keyboardShortcuts', () => {
3439
expect(enabled.value).toBe(true)
3540
})
3641

37-
it('should be reactive', () => {
42+
it('should be reactive', async () => {
43+
const { useSettings } = await import('../../../app/composables/useSettings')
44+
const { useKeyboardShortcuts } = await import('../../../app/composables/useSettings')
3845
const { settings } = useSettings()
3946
const enabled = useKeyboardShortcuts()
4047

@@ -46,15 +53,17 @@ describe('useSettings - keyboardShortcuts', () => {
4653
})
4754

4855
describe('persistence', () => {
49-
it('should persist keyboardShortcuts=false to localStorage', () => {
56+
it('should persist keyboardShortcuts=false to localStorage', async () => {
57+
const { useSettings } = await import('../../../app/composables/useSettings')
5058
const { settings } = useSettings()
5159
settings.value.keyboardShortcuts = false
5260

5361
const stored = JSON.parse(localStorage.getItem('npmx-settings') ?? '{}')
5462
expect(stored.keyboardShortcuts).toBe(false)
5563
})
5664

57-
it('should persist keyboardShortcuts=true to localStorage', () => {
65+
it('should persist keyboardShortcuts=true to localStorage', async () => {
66+
const { useSettings } = await import('../../../app/composables/useSettings')
5867
const { settings } = useSettings()
5968
settings.value.keyboardShortcuts = false
6069
settings.value.keyboardShortcuts = true

0 commit comments

Comments
 (0)