@@ -20,26 +20,16 @@ describe('Positioning', () => {
20
20
return element ;
21
21
}
22
22
23
- let cleanUp = false ;
24
23
let element = createElement ( 200 , 300 , 100 , 150 ) ;
24
+ document . body . appendChild ( element ) ;
25
+ let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
26
+ document . body . appendChild ( targetElement ) ;
25
27
26
28
document . documentElement . style . margin = '0' ;
27
29
document . body . style . margin = '0' ;
28
30
document . body . style . height = '2000px' ;
29
31
document . body . style . width = '2000px' ;
30
32
31
- beforeEach ( ( ) => {
32
- if ( ! cleanUp ) {
33
- document . body . appendChild ( element ) ;
34
- }
35
- } ) ;
36
-
37
- afterEach ( ( ) => {
38
- if ( ! cleanUp ) {
39
- document . body . removeChild ( element ) ;
40
- }
41
- } ) ;
42
-
43
33
it ( 'should calculate the element offset' , ( ) => {
44
34
let position = positioning . offset ( element ) ;
45
35
@@ -110,151 +100,92 @@ describe('Positioning', () => {
110
100
} ) ;
111
101
112
102
it ( 'should position the element top-left' , ( ) => {
113
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
114
- document . body . appendChild ( targetElement ) ;
115
-
116
103
let position = positioning . positionElements ( element , targetElement , 'top-left' ) ;
117
104
118
105
expect ( position . top ) . toBe ( 50 ) ;
119
106
expect ( position . left ) . toBe ( 150 ) ;
120
-
121
- document . body . removeChild ( targetElement ) ;
122
107
} ) ;
123
108
124
109
it ( 'should position the element top-center' , ( ) => {
125
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
126
- document . body . appendChild ( targetElement ) ;
127
-
128
110
let position = positioning . positionElements ( element , targetElement , 'top' ) ;
129
111
130
112
expect ( position . top ) . toBe ( 50 ) ;
131
113
expect ( position . left ) . toBe ( 250 ) ;
132
-
133
- document . body . removeChild ( targetElement ) ;
134
114
} ) ;
135
115
136
116
it ( 'should position the element top-right' , ( ) => {
137
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
138
- document . body . appendChild ( targetElement ) ;
139
-
140
117
let position = positioning . positionElements ( element , targetElement , 'top-right' ) ;
141
118
142
119
expect ( position . top ) . toBe ( 50 ) ;
143
120
expect ( position . left ) . toBe ( 450 ) ;
144
-
145
- document . body . removeChild ( targetElement ) ;
146
121
} ) ;
147
122
148
123
it ( 'should position the element bottom-left' , ( ) => {
149
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
150
- document . body . appendChild ( targetElement ) ;
151
-
152
124
let position = positioning . positionElements ( element , targetElement , 'bottom-left' ) ;
153
125
154
126
expect ( position . top ) . toBe ( 300 ) ;
155
127
expect ( position . left ) . toBe ( 150 ) ;
156
-
157
- document . body . removeChild ( targetElement ) ;
158
128
} ) ;
159
129
160
130
it ( 'should position the element bottom-center' , ( ) => {
161
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
162
- document . body . appendChild ( targetElement ) ;
163
-
164
131
let position = positioning . positionElements ( element , targetElement , 'bottom' ) ;
165
132
166
133
expect ( position . top ) . toBe ( 300 ) ;
167
134
expect ( position . left ) . toBe ( 250 ) ;
168
-
169
- document . body . removeChild ( targetElement ) ;
170
135
} ) ;
171
136
172
137
it ( 'should position the element bottom-right' , ( ) => {
173
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
174
- document . body . appendChild ( targetElement ) ;
175
-
176
138
let position = positioning . positionElements ( element , targetElement , 'bottom-right' ) ;
177
139
178
140
expect ( position . top ) . toBe ( 300 ) ;
179
141
expect ( position . left ) . toBe ( 450 ) ;
180
-
181
- document . body . removeChild ( targetElement ) ;
182
142
} ) ;
183
143
184
144
it ( 'should position the element left-top' , ( ) => {
185
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
186
- document . body . appendChild ( targetElement ) ;
187
-
188
145
let position = positioning . positionElements ( element , targetElement , 'left-top' ) ;
189
146
190
147
expect ( position . top ) . toBe ( 100 ) ;
191
148
expect ( position . left ) . toBe ( 50 ) ;
192
-
193
- document . body . removeChild ( targetElement ) ;
194
149
} ) ;
195
150
196
151
it ( 'should position the element left-center' , ( ) => {
197
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
198
- document . body . appendChild ( targetElement ) ;
199
-
200
152
let position = positioning . positionElements ( element , targetElement , 'left' ) ;
201
153
202
154
expect ( position . top ) . toBe ( 175 ) ;
203
155
expect ( position . left ) . toBe ( 50 ) ;
204
-
205
- document . body . removeChild ( targetElement ) ;
206
156
} ) ;
207
157
208
158
it ( 'should position the element left-bottom' , ( ) => {
209
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
210
- document . body . appendChild ( targetElement ) ;
211
-
212
159
let position = positioning . positionElements ( element , targetElement , 'left-bottom' ) ;
213
160
214
161
expect ( position . top ) . toBe ( 300 ) ;
215
162
expect ( position . left ) . toBe ( 50 ) ;
216
-
217
- document . body . removeChild ( targetElement ) ;
218
163
} ) ;
219
164
220
165
it ( 'should position the element right-top' , ( ) => {
221
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
222
- document . body . appendChild ( targetElement ) ;
223
-
224
166
let position = positioning . positionElements ( element , targetElement , 'right-top' ) ;
225
167
226
168
expect ( position . top ) . toBe ( 100 ) ;
227
169
expect ( position . left ) . toBe ( 450 ) ;
228
-
229
- document . body . removeChild ( targetElement ) ;
230
170
} ) ;
231
171
232
172
it ( 'should position the element right-center' , ( ) => {
233
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
234
- document . body . appendChild ( targetElement ) ;
235
-
236
173
let position = positioning . positionElements ( element , targetElement , 'right' ) ;
237
174
238
175
expect ( position . top ) . toBe ( 175 ) ;
239
176
expect ( position . left ) . toBe ( 450 ) ;
240
-
241
- document . body . removeChild ( targetElement ) ;
242
177
} ) ;
243
178
244
179
it ( 'should position the element right-bottom' , ( ) => {
245
- let targetElement = createElement ( 50 , 100 , 10 , 20 ) ;
246
- document . body . appendChild ( targetElement ) ;
247
-
248
180
let position = positioning . positionElements ( element , targetElement , 'right-bottom' ) ;
249
181
250
182
expect ( position . top ) . toBe ( 300 ) ;
251
183
expect ( position . left ) . toBe ( 450 ) ;
252
-
253
- document . body . removeChild ( targetElement ) ;
254
184
} ) ;
255
185
256
186
it ( 'cleanUp' , ( ) => {
257
- cleanUp = true ;
187
+ document . body . removeChild ( element ) ;
188
+ document . body . removeChild ( targetElement ) ;
258
189
document . documentElement . style . margin = documentMargin ;
259
190
document . body . style . margin = bodyMargin ;
260
191
document . body . style . height = bodyHeight ;
0 commit comments