|
1 | 1 | import * as test from 'node:test' |
2 | 2 | import * as assert from 'node:assert/strict' |
3 | | -import * as s from 'solid-js' |
4 | 3 | import * as sw from 'solid-js/web' |
5 | | -import * as jsdom from 'jsdom' |
6 | 4 |
|
7 | | -// Setup JSDOM environment |
8 | | -const dom = new jsdom.JSDOM('<!DOCTYPE html><div id="app"></div>') |
9 | | -global.window = dom.window as any |
10 | | -global.document = dom.window.document |
11 | | -global.DocumentFragment = dom.window.DocumentFragment |
| 5 | +import {TestComponent} from './component.tsx' |
12 | 6 |
|
13 | 7 | const app = document.getElementById('app')! |
14 | 8 |
|
15 | 9 | test.test('Solid Client-side Rendering', () => { |
16 | 10 |
|
17 | | - const [count, setCount] = s.createSignal(0) |
| 11 | + const dispose = sw.render(() => <TestComponent message='Hello Client!'/>, app) |
18 | 12 |
|
19 | | - let counter!: HTMLParagraphElement |
20 | | - |
21 | | - const dispose = sw.render(() => <> |
22 | | - <div> |
23 | | - <h1>Client Test</h1> |
24 | | - <p ref={counter}>Count: {count()}</p> |
25 | | - </div> |
26 | | - </>, app) |
27 | | - |
28 | | - assert.equal(app.querySelector('h1')!.textContent, 'Client Test', 'Should render h1 with correct text') |
| 13 | + assert.equal(app.querySelector('h1')!.textContent, 'Hello Client!', 'Should render h1 with correct text') |
29 | 14 |
|
| 15 | + const counter = app.querySelector('button')!; |
30 | 16 | assert.equal(counter.textContent, 'Count: 0', 'Should render initial count value') |
31 | 17 |
|
32 | | - setCount(1) |
| 18 | + counter.click(); |
33 | 19 |
|
34 | | - assert.equal(counter.textContent, 'Count: 1', 'Count should increment after setting count to 1') |
| 20 | + assert.equal(counter.textContent, 'Count: 1', 'Count should increment after button click') |
35 | 21 |
|
36 | 22 | dispose() |
37 | 23 | }) |
0 commit comments