fix imports

This commit is contained in:
Dominik Pschenitschni 2022-04-23 13:06:34 +02:00 committed by Gitea
parent 50e297183c
commit d325810e55

View file

@ -1,15 +1,15 @@
import {test, expect, fn} from 'vitest' import {test, expect, vi} from 'vitest'
import {getHistory, removeListFromHistory, saveListToHistory} from './listHistory' import {getHistory, removeListFromHistory, saveListToHistory} from './listHistory'
test('return an empty history when none was saved', () => { test('return an empty history when none was saved', () => {
Storage.prototype.getItem = fn(() => null) Storage.prototype.getItem = vi.fn(() => null)
const h = getHistory() const h = getHistory()
expect(h).toStrictEqual([]) expect(h).toStrictEqual([])
}) })
test('return a saved history', () => { test('return a saved history', () => {
const saved = [{id: 1}, {id: 2}] const saved = [{id: 1}, {id: 2}]
Storage.prototype.getItem = fn(() => JSON.stringify(saved)) Storage.prototype.getItem = vi.fn(() => JSON.stringify(saved))
const h = getHistory() const h = getHistory()
expect(h).toStrictEqual(saved) expect(h).toStrictEqual(saved)
@ -17,8 +17,8 @@ test('return a saved history', () => {
test('store list in history', () => { test('store list in history', () => {
let saved = {} let saved = {}
Storage.prototype.getItem = fn(() => null) Storage.prototype.getItem = vi.fn(() => null)
Storage.prototype.setItem = fn((key, lists) => { Storage.prototype.setItem = vi.fn((key, lists) => {
saved = lists saved = lists
}) })
@ -28,8 +28,8 @@ test('store list in history', () => {
test('store only the last 5 lists in history', () => { test('store only the last 5 lists in history', () => {
let saved: string | null = null let saved: string | null = null
Storage.prototype.getItem = fn(() => saved) Storage.prototype.getItem = vi.fn(() => saved)
Storage.prototype.setItem = fn((key: string, lists: string) => { Storage.prototype.setItem = vi.fn((key: string, lists: string) => {
saved = lists saved = lists
}) })
@ -44,8 +44,8 @@ test('store only the last 5 lists in history', () => {
test('don\'t store the same list twice', () => { test('don\'t store the same list twice', () => {
let saved: string | null = null let saved: string | null = null
Storage.prototype.getItem = fn(() => saved) Storage.prototype.getItem = vi.fn(() => saved)
Storage.prototype.setItem = fn((key: string, lists: string) => { Storage.prototype.setItem = vi.fn((key: string, lists: string) => {
saved = lists saved = lists
}) })
@ -56,8 +56,8 @@ test('don\'t store the same list twice', () => {
test('move a list to the beginning when storing it multiple times', () => { test('move a list to the beginning when storing it multiple times', () => {
let saved: string | null = null let saved: string | null = null
Storage.prototype.getItem = fn(() => saved) Storage.prototype.getItem = vi.fn(() => saved)
Storage.prototype.setItem = fn((key: string, lists: string) => { Storage.prototype.setItem = vi.fn((key: string, lists: string) => {
saved = lists saved = lists
}) })
@ -69,11 +69,11 @@ test('move a list to the beginning when storing it multiple times', () => {
test('remove list from history', () => { test('remove list from history', () => {
let saved: string | null = '[{"id": 1}]' let saved: string | null = '[{"id": 1}]'
Storage.prototype.getItem = fn(() => null) Storage.prototype.getItem = vi.fn(() => null)
Storage.prototype.setItem = fn((key: string, lists: string) => { Storage.prototype.setItem = vi.fn((key: string, lists: string) => {
saved = lists saved = lists
}) })
Storage.prototype.removeItem = fn((key: string) => { Storage.prototype.removeItem = vi.fn((key: string) => {
saved = null saved = null
}) })