-
Notifications
You must be signed in to change notification settings - Fork 0
/
observable-elements.spec.tsx
58 lines (50 loc) · 1.31 KB
/
observable-elements.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { expect, it, describe } from "@jest/globals"
import { BehaviorSubject, Subscription } from "rxjs"
import { renderSpec } from "jsx-view"
function expectSpec(structure: JSX.Element) {
return expect(renderSpec(new Subscription(), structure))
}
describe("observable elements", () => {
it("renders div with behavior", () => {
const $label$ = new BehaviorSubject("Hello")
const expectDom = expectSpec(<div style={$label$}>{$label$}</div>)
expectDom.toMatchInlineSnapshot(`
<div
style="Hello"
>
<jsx-view-observable>
Hello
</jsx-view-observable>
</div>
`)
$label$.next("Hello, Steve!")
expectDom.toMatchInlineSnapshot(`
<div
style="Hello, Steve!"
>
<jsx-view-observable>
Hello, Steve!
</jsx-view-observable>
</div>
`)
})
it("renders div with jsx behavior", () => {
const $label$ = new BehaviorSubject<JSX.Child>("Hello")
const expectDom = expectSpec(<div>{$label$}</div>)
expectDom.toMatchInlineSnapshot(`
<div>
<jsx-view-observable>
Hello
</jsx-view-observable>
</div>
`)
$label$.next(<label>Hello</label>)
expectDom.toMatchInlineSnapshot(`
<div>
<label>
Hello
</label>
</div>
`)
})
})