Skip to content

Commit a140ade

Browse files
committed
Fix indexedDB errors in tests
1 parent 65238fa commit a140ade

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"@types/react": "^18.3.4",
7474
"@types/react-dom": "^18.3.0",
7575
"dotenv": "^16.4.5",
76+
"fake-indexeddb": "^6.0.0",
7677
"happy-dom": "^15.7.0",
7778
"jsdom": "^25.0.0",
7879
"storybook": "^8.2.9",

src/common/components/TextInput/TextInput.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import "@testing-library/jest-dom";
2+
import "fake-indexeddb/auto";
23
import { render, screen } from "@testing-library/react";
4+
// this import needs to be before the TextInput import
35
import { TextInput } from "./TextInput";
46
import { describe, it } from "vitest";
57

src/scripts/db/SparkService.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { vi } from "vitest";
2+
// this import needs to be before the spark service import
3+
import "fake-indexeddb/auto";
24
import { SparkService } from "./SparkService";
35
import type AppDB from "./AppDB";
46

@@ -14,11 +16,24 @@ describe("SparkService", () => {
1416
update: vi.fn(),
1517
delete: vi.fn(),
1618
orderBy: vi.fn().mockReturnValue({
17-
reverse: vi.fn().mockReturnValue({ toArray: toArrayMock }),
19+
reverse: vi.fn().mockReturnValue({
20+
filter: vi.fn().mockReturnValue({
21+
toArray: toArrayMock,
22+
}),
23+
toArray: toArrayMock,
24+
}),
1825
}),
1926
toCollection: vi.fn().mockReturnValue({
2027
reverse: vi.fn().mockReturnValue({ sortBy: vi.fn() }),
2128
}),
29+
clear: vi.fn(),
30+
},
31+
tags: {
32+
where: vi.fn().mockReturnValue({
33+
anyOf: vi.fn().mockReturnValue({
34+
toArray: vi.fn(),
35+
}),
36+
}),
2237
},
2338
} as unknown as AppDB;
2439
sparkService = new SparkService(db);

src/scripts/db/SparkService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from "../../interfaces/Spark";
88
import { parseSpark, stringToHue } from "../utils/stringUtils";
99
import { tagService } from "./TagService";
10-
import type { PlainTag } from "../../interfaces/Tag";
1110

1211
export class SparkService {
1312
constructor(private db: AppDB) {}

0 commit comments

Comments
 (0)