Skip to content

Commit f384bc2

Browse files
committed
chore: add test utils from melt4 + vitest-axe
1 parent 5dbe746 commit f384bc2

File tree

5 files changed

+201
-102
lines changed

5 files changed

+201
-102
lines changed

packages/melt/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"@sveltejs/kit": "^2.15.2",
5858
"@sveltejs/package": "^2.3.9",
5959
"@sveltejs/vite-plugin-svelte": "^5.0.3",
60-
"jsdom": "^24.1.0",
6160
"publint": "^0.1.9",
6261
"svelte": "5.34.8",
6362
"svelte-check": "^4.1.3",
@@ -70,8 +69,8 @@
7069
"@floating-ui/dom": "^1.6.13",
7170
"dequal": "^2.0.3",
7271
"focus-trap": "^7.6.5",
73-
"jest-axe": "^9.0.0",
74-
"runed": "^0.23.3"
72+
"runed": "^0.23.3",
73+
"vitest-axe": "1.0.0-pre.3"
7574
},
7675
"publishConfig": {
7776
"access": "public"

packages/melt/src/lib/utils/test.svelte.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { flushSync } from "svelte";
22
import { test, vi } from "vitest";
3+
import { kbd } from "./keyboard";
34

45
export function testWithEffect(
56
name: string,
@@ -32,3 +33,22 @@ export function focus(node: HTMLElement | null | undefined) {
3233
flushSync(() => node.focus());
3334
}
3435
}
36+
37+
type KbdKeys = keyof typeof kbd;
38+
/**
39+
* A wrapper around the internal kbd object to make it easier to use
40+
* in tests which require the key names to be wrapped in curly braces.
41+
*/
42+
export const testKbd: Record<KbdKeys, string> = Object.entries(kbd).reduce((acc, [key, value]) => {
43+
acc[key as KbdKeys] = `{${value}}`;
44+
return acc;
45+
}, {} as Record<KbdKeys, string>);
46+
47+
export function exists(get: (id: string) => HTMLElement, testId: string) {
48+
try {
49+
get(testId);
50+
return true;
51+
} catch {
52+
return false;
53+
}
54+
}

packages/melt/svelte.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const config = {
55
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
66
// for more information about preprocessors
77
preprocess: vitePreprocess(),
8-
8+
compilerOptions: {
9+
runes: true,
10+
},
911
kit: {},
1012
};
1113

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/// <reference types="@vitest/browser/matchers" />
22
/// <reference types="@vitest/browser/providers/playwright" />
3+
/// <reference types="vitest-axe/extend-expect" />

0 commit comments

Comments
 (0)