|
1 | 1 | namespace App |
2 | 2 |
|
3 | | -open Fable.Core.JsInterop |
4 | 3 | open Fable.Core |
5 | | -open Feliz.JSX.Solid |
6 | | - |
7 | | -// https://vitest.dev/config/#environment |
8 | | -// https://docs.solidjs.com/guides/testing |
9 | | -// https://github.com/fable-compiler/Feliz.JSX |
10 | | -// https://fable.io/blog/2022/2022-10-18-fable-solid.html |
11 | | -// https://github.com/fable-compiler/Fable.Solid |
12 | | - |
13 | | -// IMPORTANT! https://fable.io/docs/javascript/features.html |
14 | | - |
15 | | -// as inspiration for types: https://github.com/Shmew/Fable.Jester/blob/master/src/Fable.Jester/Expect.fs |
16 | | - |
17 | | -module Dom = |
18 | | - open Fable.Core.JsInterop |
19 | | - open Fable.Core |
20 | | - |
21 | | - type IRenderResult = |
22 | | - abstract getByText: string -> obj |
23 | | - abstract getByRole: string -> obj |
24 | | - |
25 | | - type DomEvent = { |
26 | | - click: obj -> unit |
27 | | - } |
28 | | - |
29 | | - [<Import("render", from = "@solidjs/testing-library")>] |
30 | | - let render (fableComponent: obj) : IRenderResult = jsNative |
31 | | - |
32 | | - [<Import("cleanup", from = "@solidjs/testing-library")>] |
33 | | - let cleanup(): unit = jsNative |
34 | | - |
35 | | - [<Import("screen", from = "@solidjs/testing-library")>] |
36 | | - let screen: IRenderResult = jsNative |
37 | | - |
38 | | - [<Import("fireEvent", from = "@solidjs/testing-library")>] |
39 | | - let fireEvent: DomEvent = jsNative |
40 | | - |
41 | | -// for each Fable import try to match JS signature and try create |
42 | | -// correct types based on original typescript definitions but as F# types e.g. record types |
43 | | - |
44 | | -module Vi = |
45 | | - type IMatcherResult = |
46 | | - abstract toBe: obj -> unit |
47 | | - abstract toEqual: obj -> unit |
48 | | - abstract toMatchObject: obj -> unit |
49 | | - abstract toHaveBeenCalled: unit -> unit |
50 | | - abstract toHaveBeenCalledWith: obj -> unit |
51 | | - abstract toHaveBeenCalledTimes: int -> unit |
52 | | - abstract toBeInTheDocument: unit -> unit |
53 | | - abstract toHaveTextContent: string -> unit |
54 | | - abstract toHaveClass: string -> unit |
55 | | - abstract toHaveStyle: string -> unit |
56 | | - abstract toHaveAttribute: string -> unit |
57 | | - abstract toHaveProperty: string -> unit |
58 | | - abstract toHaveValue: string -> unit |
59 | | - abstract toHaveFocus: unit -> unit |
60 | | - abstract toHaveFormValues: obj -> unit |
61 | | - abstract toHaveLength: int -> unit |
62 | | - abstract toBeDisabled: unit -> unit |
63 | | - abstract toBeEnabled: unit -> unit |
64 | | - abstract toBeVisible: unit -> unit |
65 | | - abstract toBeEmpty: unit -> unit |
66 | | - abstract toBeChecked: unit -> unit |
67 | | - abstract toBeSelected: unit -> unit |
68 | | - abstract toBeTruthy: unit -> unit |
69 | | - abstract toBeFalsy: unit -> unit |
70 | | - abstract toBeNull: unit -> unit |
71 | | - abstract toBeUndefined: unit -> unit |
72 | | - abstract toBeNaN: unit -> unit |
73 | | - abstract toBeGreaterThan: obj -> unit |
74 | | - abstract toBeLessThan: obj -> unit |
75 | | - abstract toBeGreaterThanOrEqual: obj -> unit |
76 | | - abstract toBeLessThanOrEqual: obj -> unit |
77 | | - abstract toBeCloseTo: obj -> unit |
78 | | - |
79 | | - [<Import("expect", from = "vitest")>] |
80 | | - let expect(value: obj): IMatcherResult = jsNative |
81 | | - |
82 | | - [<Import("toBeInTheDocument", from = "@testing-library/jest-dom/matchers")>] |
83 | | - let toBeInTheDocument: obj = jsNative |
84 | | - |
85 | | - // Extension method for expect |
86 | | - [<Emit("$0.toBeInTheDocument()")>] |
87 | | - let inline expectToBeInTheDocument (value: obj): obj = jsNative |
88 | | - |
89 | | - [<Import("beforeEach", from = "vitest")>] |
90 | | - let beforeEach(test: unit -> unit) = jsNative |
91 | | - |
92 | | - [<Import("afterEach", from = "vitest")>] |
93 | | - let afterEach(test: unit -> unit) = jsNative |
94 | | - |
95 | | - [<Import("beforeAll", from = "vitest")>] |
96 | | - let beforeAll(test: unit -> unit) = jsNative |
97 | | - |
98 | | - [<Import("afterAll", from = "vitest")>] |
99 | | - let afterAll(test: unit -> unit) = jsNative |
100 | | - |
101 | | - [<Import("it", from = "vitest")>] |
102 | | - let it(name: string, test: unit -> unit) = jsNative |
103 | | - |
104 | | - [<Import("test", from = "vitest")>] |
105 | | - let test(name: string, test: unit -> unit) = jsNative |
106 | | - |
107 | | - [<Import("describe", from = "vitest")>] |
108 | | - let describe(name: string, testSuite: unit -> unit) = jsNative |
109 | | - |
| 4 | +open Testing |
110 | 5 |
|
111 | 6 | module Test = |
112 | 7 |
|
|
0 commit comments