@llui/test 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,81 @@
|
|
|
1
1
|
# @llui/test
|
|
2
2
|
|
|
3
|
-
Test harness for [LLui](https://github.com/fponticelli/llui) components.
|
|
4
|
-
|
|
5
|
-
`testComponent`, `testView`, `propertyTest`, `replayTrace`, `assertEffects` — mount components in jsdom, send messages, assert on state + DOM.
|
|
3
|
+
Test harness for [LLui](https://github.com/fponticelli/llui) components. Mount components in jsdom, send messages, and assert on state and DOM.
|
|
6
4
|
|
|
7
5
|
```bash
|
|
8
6
|
pnpm add -D @llui/test
|
|
9
7
|
```
|
|
10
8
|
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { testView } from '@llui/test'
|
|
13
|
+
import { counterDef } from './counter'
|
|
14
|
+
|
|
15
|
+
const harness = testView(counterDef, { count: 0 })
|
|
16
|
+
|
|
17
|
+
harness.click('[data-testid="increment"]')
|
|
18
|
+
harness.flush()
|
|
19
|
+
|
|
20
|
+
expect(harness.text('[data-testid="display"]')).toBe('1')
|
|
21
|
+
harness.unmount()
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API
|
|
25
|
+
|
|
26
|
+
### testComponent
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
testComponent(def) => { state, send, flush, effects }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Mount a component definition headlessly. Returns current state snapshot and message dispatch.
|
|
33
|
+
|
|
34
|
+
### testView
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
testView(def, state?) => ViewHarness<M>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Mount a component into jsdom with full DOM. Returns a harness with DOM query and interaction methods.
|
|
41
|
+
|
|
42
|
+
| Method | Description |
|
|
43
|
+
| ------------------------ | ----------------------------------------------- |
|
|
44
|
+
| `.send(msg)` | Dispatch a message |
|
|
45
|
+
| `.flush()` | Force synchronous update (skip microtask queue) |
|
|
46
|
+
| `.click(selector)` | Simulate click on element |
|
|
47
|
+
| `.input(selector, val)` | Set input value and fire input event |
|
|
48
|
+
| `.text(selector)` | Get textContent of element |
|
|
49
|
+
| `.attr(selector, name)` | Get attribute value |
|
|
50
|
+
| `.query(selector)` | querySelector on mounted DOM |
|
|
51
|
+
| `.queryAll(selector)` | querySelectorAll on mounted DOM |
|
|
52
|
+
| `.fire(selector, event)` | Dispatch a custom event |
|
|
53
|
+
| `.unmount()` | Tear down the component and clean up |
|
|
54
|
+
|
|
55
|
+
### assertEffects
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
assertEffects(effects, expected) => void
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Deep-equal assertion on effect arrays. Provides clear diff output on mismatch.
|
|
62
|
+
|
|
63
|
+
### propertyTest
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
propertyTest(gen, prop) => void
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Property-based testing. Generates random inputs via `gen` and checks `prop` holds for all.
|
|
70
|
+
|
|
71
|
+
### replayTrace
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
replayTrace(def, trace) => void
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Replay a recorded message trace against a component definition. Asserts state at each step.
|
|
78
|
+
|
|
11
79
|
## License
|
|
12
80
|
|
|
13
81
|
MIT
|