Skip to content

Commit 2986043

Browse files
authored
test: add test examples via vitest (#158)
* test: add test examples via vitest * fix: add the tests to vite-6 + update deps
1 parent 85e6f45 commit 2986043

File tree

5 files changed

+1236
-5
lines changed

5 files changed

+1236
-5
lines changed

examples/vite-6/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
"scripts": {
66
"dev": "vite",
77
"build": "vite build",
8-
"preview": "vite preview"
8+
"preview": "vite preview",
9+
"test": "vitest"
910
},
1011
"devDependencies": {
11-
"vite": "^6.0.0",
12-
"vite-plugin-solid": "workspace:*"
12+
"@solidjs/testing-library": "^0.8.10",
13+
"@testing-library/jest-dom": "^6.6.3",
14+
"@testing-library/user-event": "^14.6.1",
15+
"jsdom": "^26.0.0",
16+
"vite": "^6.2.0",
17+
"vite-plugin-solid": "workspace:*",
18+
"vitest": "^3.0.7"
1319
},
1420
"dependencies": {
1521
"solid-js": "catalog:"

examples/vite-6/tests/App.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect, test } from 'vitest';
2+
import { render } from '@solidjs/testing-library';
3+
import user from '@testing-library/user-event';
4+
5+
import App from '../src/App.jsx';
6+
7+
test('App', async () => {
8+
const { getByText } = render(() => <App />);
9+
10+
const counterTitle = getByText('Counter');
11+
12+
const count = counterTitle.nextElementSibling as HTMLElement;
13+
expect(count).instanceOf(HTMLElement);
14+
expect(count.innerHTML).toContain('Count: 0');
15+
16+
const incrementButton = getByText('Increment');
17+
await user.click(incrementButton);
18+
expect(count.innerHTML).toContain('Count: 1');
19+
20+
const decrementButton = getByText('Decrement');
21+
await user.click(decrementButton);
22+
expect(count.innerHTML).toContain('Count: 0');
23+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"types": [
5+
"@testing-library/jest-dom"
6+
]
7+
},
8+
"include": [
9+
"**/*.ts",
10+
"**/*.tsx"
11+
]
12+
}

examples/vite-6/vitest.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from 'vitest/config';
2+
import solidPlugin from '../../src/index.js';
3+
4+
export default defineConfig({
5+
plugins: [solidPlugin()],
6+
resolve: {
7+
conditions: ['development', 'browser'],
8+
},
9+
});

0 commit comments

Comments
 (0)