-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathJSX_API.fs
More file actions
96 lines (72 loc) · 3.06 KB
/
Copy pathJSX_API.fs
File metadata and controls
96 lines (72 loc) · 3.06 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
module Fable.Tests.JSX_API
open Fable.Core
open Fable.Core.JsInterop
open Fable.Jester
open Fable.ReactTestingLibrary
open JsxListOptimisation
// Necessary for JSX compilation
let React: obj = importAll "react"
// Expose a render version to work directly with JSX.Element
type RTL with
static member inline render (jsxElement: JSX.Element) =
RTL.render(unbox<Feliz.ReactElement> jsxElement)
static member inline render (jsxElement: Components.JSX_ReactElement) =
RTL.render(unbox<Feliz.ReactElement> jsxElement)
let private matchSnapshot (element : Components.JSX_ReactElement)=
element
|> RTL.render
|> _.container
|> Jest.expect
|> _.toMatchSnapshot()
Jest.describe("JSX API tests (using React)", fun () ->
Jest.test("Element can have text directly in them", fun () ->
matchSnapshot Components.divWithText
)
Jest.test("Element can have nested list", fun () ->
matchSnapshot Components.divWithNestedList
)
Jest.test("Element can have multiple nested list", fun () ->
matchSnapshot Components.divWithMultipleNestedList
)
Jest.test("Element can have mix of element and list", fun () ->
matchSnapshot Components.divWithMixOfElementAndList
)
Jest.test("Element can have multi level mix of element and list", fun () ->
matchSnapshot Components.multiLevelMixOfElementAndList
)
Jest.test("Test that optimised condition works for the true branch", fun () ->
matchSnapshot Components.divWithOptimisedTrueCondition
)
Jest.test("Test that optimised condition works for the false branch", fun () ->
matchSnapshot Components.divWithOptimisedFalseCondition
)
Jest.test("Test that non optimised condition works", fun () ->
let mutable myCondition = "a"
myCondition |> ignore
matchSnapshot (Components.divWithConditionalChildren myCondition)
)
Jest.test("Element can have for loops", fun () ->
matchSnapshot Components.divWithForLoop
)
Jest.test("Element can have a match arm that binds a value before a for loop", fun () ->
matchSnapshot (Components.divWithMatchContainingForLoop 2)
)
Jest.test("Element can have a sibling before a match arm that binds a value before a for loop", fun () ->
matchSnapshot (Components.divWithElementBeforeMatchContainingForLoop 2)
)
Jest.test("Fragments are supported", fun () ->
matchSnapshot Components.divWithFragment
)
Jest.test("Elements can have attributes", fun () ->
matchSnapshot Components.divWithAttributes
)
Jest.test("Test that condition without else branch works if condition is True", fun () ->
matchSnapshot (Components.divWithConditionalWithoutElseBranchWorks true)
)
Jest.test("Test that condition without else branch works if condition is False", fun () ->
matchSnapshot (Components.divWithConditionalWithoutElseBranchWorks false)
)
Jest.test("Test that properties can be defined using `unbox`", fun () ->
matchSnapshot Components.propsCanUseUnbox
)
)