diff --git a/bun.lockb b/bun.lockb index f592e42..624c3fe 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index abfbf7b..a11bdce 100644 --- a/package.json +++ b/package.json @@ -18,12 +18,18 @@ "dev": "vinxi dev", "build": "vinxi build", "start": "vinxi start", - "version": "vinxi version" + "version": "vinxi version", + "test": "vitest" }, "type": "module", "devDependencies": { + "@solidjs/testing-library": "^0.8.10", + "@testing-library/jest-dom": "^6.6.3", + "@testing-library/user-event": "^14.5.2", "@types/wicg-file-system-access": "^2023.10.5", + "jsdom": "^25.0.1", "vite-plugin-pwa": "^0.20.5", + "vitest": "^2.1.4", "workbox-window": "^7.3.0" } } \ No newline at end of file diff --git a/src/utilities.spec.ts b/src/utilities.spec.ts new file mode 100644 index 0000000..46e096c --- /dev/null +++ b/src/utilities.spec.ts @@ -0,0 +1,22 @@ +import { expect, describe, it, beforeEach, vi } from "vitest" +import { debounce } from "./utilities" + +describe('debounce', () => { + beforeEach(() => { + vi.useFakeTimers(); + }) + + it('should run the given callback after the provided time', async () => { + // Arrange + const callback = vi.fn(() => { }); + const delay = 1000; + const debounced = debounce(callback, delay); + + // Act + debounced(); + vi.runAllTimers(); + + // Assert + expect(callback).toHaveBeenCalled(); + }); +}); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 8b38339..65df43c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,8 +12,9 @@ "noEmit": true, "types": [ "@solidjs/start/env", - "vinxi/types/client", + "@testing-library/jest-dom", "@types/wicg-file-system-access", + "vinxi/types/client", "vite-plugin-pwa/solid" ], "isolatedModules": true, diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..a13a54d --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,10 @@ +import solid from "vite-plugin-solid" +import { defineConfig } from "vitest/config" + +export default defineConfig({ + plugins: [solid()], + root: './src', + resolve: { + conditions: ["development", "browser"], + }, +}) \ No newline at end of file