Skip to content

Commit 50f5680

Browse files
committed
test: adjust tests for updated vitest
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent ea2c1d9 commit 50f5680

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

test/index.test.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,10 @@
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
55

6-
import { expect, test, vi } from 'vitest'
6+
import { beforeEach, expect, test, vi } from 'vitest'
77
import { loadState } from '../lib/index.ts'
88

9-
/**
10-
* Mock initial state input elements
11-
* @param app first part of the key
12-
* @param key second part of the key
13-
* @param value value to be stored
14-
*/
15-
function appendInput(app: string, key: string, value: string) {
16-
const input = document.createElement('input')
17-
input.setAttribute('type', 'hidden')
18-
input.setAttribute('id', `initial-state-${app}-${key}`)
19-
input.setAttribute('value', btoa(JSON.stringify(value)))
20-
document.querySelector('body')!.appendChild(input)
21-
}
9+
beforeEach(() => vi.resetAllMocks())
2210

2311
test('throw if nothing found', () => {
2412
expect(() => loadState('test', 'key')).toThrow(new Error('Could not find initial state key of test'))
@@ -72,5 +60,19 @@ test('returns fallback if state cannot be parsed but fallback is provided', () =
7260
})
7361

7462
expect(loadState('app', 'key', 'fallback')).toBe('fallback')
75-
expect(errorLog).toHaveBeenCalledOnce()
63+
expect(errorLog).toHaveBeenCalled()
7664
})
65+
66+
/**
67+
* Mock initial state input elements
68+
* @param app first part of the key
69+
* @param key second part of the key
70+
* @param value value to be stored
71+
*/
72+
function appendInput(app: string, key: string, value: string) {
73+
const input = document.createElement('input')
74+
input.setAttribute('type', 'hidden')
75+
input.setAttribute('id', `initial-state-${app}-${key}`)
76+
input.setAttribute('value', btoa(JSON.stringify(value)))
77+
document.querySelector('body')!.appendChild(input)
78+
}

0 commit comments

Comments
 (0)