@@ -9,8 +9,12 @@ import {
9
9
DRAG_DELAY ,
10
10
drag ,
11
11
} from 'helper' ;
12
+ import { FixMeAny } from 'shared/types' ;
12
13
13
- import { Draggable } from '../../..' ;
14
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
15
+ // @ts -ignore
16
+ import Draggable from '../../../Draggable' ;
17
+ /* eslint-enable @typescript-eslint/ban-ts-comment */
14
18
import ResizeMirror from '..' ;
15
19
16
20
const sampleMarkup = `
@@ -36,17 +40,17 @@ describe('ResizeMirror', () => {
36
40
height : smallerDraggableDimensions . height * 2 ,
37
41
} ;
38
42
39
- let sandbox ;
40
- let containers ;
41
- let draggable ;
42
- let draggables ;
43
- let smallerDraggable ;
44
- let largerDraggable ;
43
+ let sandbox : HTMLDivElement ;
44
+ let containers : HTMLElement [ ] ;
45
+ let draggable : FixMeAny ;
46
+ let draggables : HTMLElement [ ] ;
47
+ let smallerDraggable : HTMLElement ;
48
+ let largerDraggable : HTMLElement ;
45
49
46
50
beforeEach ( ( ) => {
47
51
sandbox = createSandbox ( sampleMarkup ) ;
48
- containers = sandbox . querySelectorAll ( '.Container' ) ;
49
- draggables = sandbox . querySelectorAll ( 'li' ) ;
52
+ containers = [ ... sandbox . querySelectorAll < HTMLElement > ( '.Container' ) ] ;
53
+ draggables = [ ... sandbox . querySelectorAll < HTMLElement > ( 'li' ) ] ;
50
54
51
55
smallerDraggable = draggables [ 0 ] ;
52
56
largerDraggable = draggables [ 1 ] ;
@@ -71,7 +75,7 @@ describe('ResizeMirror', () => {
71
75
waitForDragDelay ( ) ;
72
76
await waitForPromisesToResolve ( ) ;
73
77
74
- const mirror = document . querySelector ( '.draggable-mirror' ) ;
78
+ const mirror = document . querySelector < HTMLElement > ( '.draggable-mirror' ) ! ;
75
79
76
80
expect ( mirror . style ) . toMatchObject ( {
77
81
width : `${ smallerDraggableDimensions . width } px` ,
@@ -104,7 +108,7 @@ describe('ResizeMirror', () => {
104
108
waitForDragDelay ( ) ;
105
109
await waitForPromisesToResolve ( ) ;
106
110
107
- const mirror = document . querySelector ( '.draggable-mirror' ) ;
111
+ const mirror = document . querySelector < HTMLElement > ( '.draggable-mirror' ) ! ;
108
112
109
113
moveMouse ( largerDraggable ) ;
110
114
waitForRequestAnimationFrame ( ) ;
@@ -119,7 +123,7 @@ describe('ResizeMirror', () => {
119
123
waitForDragDelay ( ) ;
120
124
await waitForPromisesToResolve ( ) ;
121
125
122
- const mirror = document . querySelector ( '.draggable-mirror' ) ;
126
+ const mirror = document . querySelector < HTMLElement > ( '.draggable-mirror' ) ! ;
123
127
124
128
const mockedAppendChild = withMockedAppendChild ( ( ) => {
125
129
moveMouse ( smallerDraggable ) ;
@@ -145,19 +149,28 @@ describe('ResizeMirror', () => {
145
149
} ) ;
146
150
} ) ;
147
151
148
- function mockDimensions ( element , { width = 0 , height = 0 } ) {
152
+ function mockDimensions ( element : HTMLElement , { width = 0 , height = 0 } ) {
149
153
Object . assign ( element . style , {
150
154
width : `${ width } px` ,
151
155
height : `${ height } px` ,
152
156
} ) ;
153
157
154
- element . getBoundingClientRect = ( ) => ( {
158
+ const properties = {
155
159
width,
156
160
height,
157
161
top : 0 ,
158
162
left : 0 ,
159
163
right : width ,
160
164
bottom : height ,
165
+ x : 0 ,
166
+ y : 0 ,
167
+ } ;
168
+
169
+ element . getBoundingClientRect = ( ) => ( {
170
+ ...properties ,
171
+ toJSON ( ) {
172
+ return { ...properties } ;
173
+ } ,
161
174
} ) ;
162
175
163
176
return element ;
@@ -168,13 +181,16 @@ function waitForNextRequestAnimationFrame() {
168
181
waitForRequestAnimationFrame ( ) ;
169
182
}
170
183
171
- function withMockedAppendChild ( callback ) {
184
+ function withMockedAppendChild ( callback : ( ) => void ) {
172
185
const mock = jest . fn ( ) ;
173
186
const appendChild = Node . prototype . appendChild ;
174
- Node . prototype . appendChild = function ( ...args ) {
187
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
188
+ // @ts -ignore
189
+ Node . prototype . appendChild = function ( this : Node , ...args ) {
175
190
mock ( ...args ) ;
176
191
return appendChild . call ( this , ...args ) ;
177
192
} ;
193
+ /* eslint-enable @typescript-eslint/ban-ts-comment */
178
194
callback ( ) ;
179
195
Node . prototype . appendChild = appendChild ;
180
196
return mock ;
0 commit comments