@@ -3,7 +3,7 @@ import {render, fireEvent, screen, waitFor} from '.'
3
3
import * as pure from './pure'
4
4
5
5
export async function testRender ( ) {
6
- const page = render ( < div /> )
6
+ const page = render ( < button /> )
7
7
8
8
// single queries
9
9
page . getByText ( 'foo' )
@@ -17,11 +17,12 @@ export async function testRender() {
17
17
18
18
// helpers
19
19
const { container, rerender, debug} = page
20
+ expectType < HTMLElement , typeof container > ( container )
20
21
return { container, rerender, debug}
21
22
}
22
23
23
24
export async function testPureRender ( ) {
24
- const page = pure . render ( < div /> )
25
+ const page = pure . render ( < button /> )
25
26
26
27
// single queries
27
28
page . getByText ( 'foo' )
@@ -35,13 +36,15 @@ export async function testPureRender() {
35
36
36
37
// helpers
37
38
const { container, rerender, debug} = page
39
+ expectType < HTMLElement , typeof container > ( container )
38
40
return { container, rerender, debug}
39
41
}
40
42
41
43
export function testRenderOptions ( ) {
42
44
const container = document . createElement ( 'div' )
43
45
const options = { container}
44
- render ( < div /> , options )
46
+ const { container : returnedContainer } = render ( < button /> , options )
47
+ expectType < HTMLDivElement , typeof returnedContainer > ( returnedContainer )
45
48
}
46
49
47
50
export function testSVGRenderOptions ( ) {
@@ -50,7 +53,8 @@ export function testSVGRenderOptions() {
50
53
'svg' ,
51
54
)
52
55
const options = { container}
53
- render ( < svg /> , options )
56
+ const { container : returnedContainer } = render ( < path /> , options )
57
+ expectType < SVGSVGElement , typeof returnedContainer > ( returnedContainer )
54
58
}
55
59
56
60
export function testFireEvent ( ) {
@@ -87,3 +91,27 @@ eslint
87
91
testing-library/no-debug: "off",
88
92
testing-library/prefer-screen-queries: "off"
89
93
*/
94
+
95
+ // https://stackoverflow.com/questions/53807517/how-to-test-if-two-types-are-exactly-the-same
96
+ type IfEquals < T , U , Yes = unknown , No = never > = ( < G > ( ) => G extends T
97
+ ? 1
98
+ : 2 ) extends < G > ( ) => G extends U ? 1 : 2
99
+ ? Yes
100
+ : No
101
+
102
+ /**
103
+ * Issues a type error if `Expected` is not identical to `Actual`.
104
+ *
105
+ * `Expected` should be declared when invoking `expectType`.
106
+ * `Actual` should almost always we be a `typeof value` statement.
107
+ *
108
+ * Source: https://github.com/mui-org/material-ui/blob/6221876a4b468a3330ffaafa8472de7613933b87/packages/material-ui-types/index.d.ts#L73-L84
109
+ *
110
+ * @example `expectType<number | string, typeof value>(value)`
111
+ * TypeScript issues a type error since `value is not assignable to never`.
112
+ * This means `typeof value` is not identical to `number | string`
113
+ * @param actual
114
+ */
115
+ declare function expectType < Expected , Actual > (
116
+ actual : IfEquals < Actual , Expected , Actual > ,
117
+ ) : void
0 commit comments