Skip to content

Commit 146ec1b

Browse files
RobJacobspkozlowski-opensource
authored andcommitted
fix(positioning): failing tests
Fixes ng-bootstrap#321 Closes ng-bootstrap#328 Closes ng-bootstrap#328
1 parent 61f424f commit 146ec1b

File tree

1 file changed

+5
-74
lines changed

1 file changed

+5
-74
lines changed

src/util/positioning.spec.ts

+5-74
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,16 @@ describe('Positioning', () => {
2020
return element;
2121
}
2222

23-
let cleanUp = false;
2423
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);
2527

2628
document.documentElement.style.margin = '0';
2729
document.body.style.margin = '0';
2830
document.body.style.height = '2000px';
2931
document.body.style.width = '2000px';
3032

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-
4333
it('should calculate the element offset', () => {
4434
let position = positioning.offset(element);
4535

@@ -110,151 +100,92 @@ describe('Positioning', () => {
110100
});
111101

112102
it('should position the element top-left', () => {
113-
let targetElement = createElement(50, 100, 10, 20);
114-
document.body.appendChild(targetElement);
115-
116103
let position = positioning.positionElements(element, targetElement, 'top-left');
117104

118105
expect(position.top).toBe(50);
119106
expect(position.left).toBe(150);
120-
121-
document.body.removeChild(targetElement);
122107
});
123108

124109
it('should position the element top-center', () => {
125-
let targetElement = createElement(50, 100, 10, 20);
126-
document.body.appendChild(targetElement);
127-
128110
let position = positioning.positionElements(element, targetElement, 'top');
129111

130112
expect(position.top).toBe(50);
131113
expect(position.left).toBe(250);
132-
133-
document.body.removeChild(targetElement);
134114
});
135115

136116
it('should position the element top-right', () => {
137-
let targetElement = createElement(50, 100, 10, 20);
138-
document.body.appendChild(targetElement);
139-
140117
let position = positioning.positionElements(element, targetElement, 'top-right');
141118

142119
expect(position.top).toBe(50);
143120
expect(position.left).toBe(450);
144-
145-
document.body.removeChild(targetElement);
146121
});
147122

148123
it('should position the element bottom-left', () => {
149-
let targetElement = createElement(50, 100, 10, 20);
150-
document.body.appendChild(targetElement);
151-
152124
let position = positioning.positionElements(element, targetElement, 'bottom-left');
153125

154126
expect(position.top).toBe(300);
155127
expect(position.left).toBe(150);
156-
157-
document.body.removeChild(targetElement);
158128
});
159129

160130
it('should position the element bottom-center', () => {
161-
let targetElement = createElement(50, 100, 10, 20);
162-
document.body.appendChild(targetElement);
163-
164131
let position = positioning.positionElements(element, targetElement, 'bottom');
165132

166133
expect(position.top).toBe(300);
167134
expect(position.left).toBe(250);
168-
169-
document.body.removeChild(targetElement);
170135
});
171136

172137
it('should position the element bottom-right', () => {
173-
let targetElement = createElement(50, 100, 10, 20);
174-
document.body.appendChild(targetElement);
175-
176138
let position = positioning.positionElements(element, targetElement, 'bottom-right');
177139

178140
expect(position.top).toBe(300);
179141
expect(position.left).toBe(450);
180-
181-
document.body.removeChild(targetElement);
182142
});
183143

184144
it('should position the element left-top', () => {
185-
let targetElement = createElement(50, 100, 10, 20);
186-
document.body.appendChild(targetElement);
187-
188145
let position = positioning.positionElements(element, targetElement, 'left-top');
189146

190147
expect(position.top).toBe(100);
191148
expect(position.left).toBe(50);
192-
193-
document.body.removeChild(targetElement);
194149
});
195150

196151
it('should position the element left-center', () => {
197-
let targetElement = createElement(50, 100, 10, 20);
198-
document.body.appendChild(targetElement);
199-
200152
let position = positioning.positionElements(element, targetElement, 'left');
201153

202154
expect(position.top).toBe(175);
203155
expect(position.left).toBe(50);
204-
205-
document.body.removeChild(targetElement);
206156
});
207157

208158
it('should position the element left-bottom', () => {
209-
let targetElement = createElement(50, 100, 10, 20);
210-
document.body.appendChild(targetElement);
211-
212159
let position = positioning.positionElements(element, targetElement, 'left-bottom');
213160

214161
expect(position.top).toBe(300);
215162
expect(position.left).toBe(50);
216-
217-
document.body.removeChild(targetElement);
218163
});
219164

220165
it('should position the element right-top', () => {
221-
let targetElement = createElement(50, 100, 10, 20);
222-
document.body.appendChild(targetElement);
223-
224166
let position = positioning.positionElements(element, targetElement, 'right-top');
225167

226168
expect(position.top).toBe(100);
227169
expect(position.left).toBe(450);
228-
229-
document.body.removeChild(targetElement);
230170
});
231171

232172
it('should position the element right-center', () => {
233-
let targetElement = createElement(50, 100, 10, 20);
234-
document.body.appendChild(targetElement);
235-
236173
let position = positioning.positionElements(element, targetElement, 'right');
237174

238175
expect(position.top).toBe(175);
239176
expect(position.left).toBe(450);
240-
241-
document.body.removeChild(targetElement);
242177
});
243178

244179
it('should position the element right-bottom', () => {
245-
let targetElement = createElement(50, 100, 10, 20);
246-
document.body.appendChild(targetElement);
247-
248180
let position = positioning.positionElements(element, targetElement, 'right-bottom');
249181

250182
expect(position.top).toBe(300);
251183
expect(position.left).toBe(450);
252-
253-
document.body.removeChild(targetElement);
254184
});
255185

256186
it('cleanUp', () => {
257-
cleanUp = true;
187+
document.body.removeChild(element);
188+
document.body.removeChild(targetElement);
258189
document.documentElement.style.margin = documentMargin;
259190
document.body.style.margin = bodyMargin;
260191
document.body.style.height = bodyHeight;

0 commit comments

Comments
 (0)