Skip to content

Commit 160e51b

Browse files
committed
test(overlay): move unit test config in beforeEach statement
1 parent e1afc3f commit 160e51b

File tree

1 file changed

+56
-44
lines changed

1 file changed

+56
-44
lines changed

projects/igniteui-angular/src/lib/services/overlay/overlay.spec.ts

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -190,50 +190,62 @@ describe('igxOverlay', () => {
190190

191191
describe('Pure Unit Test', () => {
192192
configureTestSuite();
193-
const mockElement: any = {
194-
style: { visibility: '', cursor: '', transitionDuration: '' },
195-
classList: { add: () => { }, remove: () => { } },
196-
appendChild: () => { },
197-
removeChild: () => { },
198-
addEventListener: (type: string, listener: (this: HTMLElement, ev: MouseEvent) => any) => { },
199-
removeEventListener: (type: string, listener: (this: HTMLElement, ev: MouseEvent) => any) => { },
200-
getBoundingClientRect: () => ({ width: 10, height: 10 }),
201-
insertBefore: (newChild: HTMLDivElement, refChild: Node) => { },
202-
contains: () => { }
203-
};
204-
mockElement.parent = mockElement;
205-
mockElement.parentElement = mockElement;
206-
const mockElementRef: any = { nativeElement: mockElement };
207-
const mockFactoryResolver: any = {
208-
resolveComponentFactory: (c: any) => {
209-
return {
210-
create: (i: any) => {
211-
return {
212-
hostView: '',
213-
location: mockElementRef,
214-
changeDetectorRef: { detectChanges: () => { } },
215-
destroy: () => { }
216-
};
217-
}
218-
};
219-
}
220-
};
221-
const mockApplicationRef: any = { attachView: (h: any) => { }, detachView: (h: any) => { } };
222-
const mockInjector: any = {};
223-
const mockAnimationBuilder: any = {};
224-
const mockDocument = {
225-
body: mockElement,
226-
defaultView: mockElement,
227-
createElement: () => mockElement,
228-
appendChild: () => { },
229-
addEventListener: (type: string, listener: (this: HTMLElement, ev: MouseEvent) => any) => { },
230-
removeEventListener: (type: string, listener: (this: HTMLElement, ev: MouseEvent) => any) => { }
231-
};
232-
const mockNgZone: any = {};
233-
const mockPlatformUtil: any = { isIOS: false };
234-
235-
const overlay = new IgxOverlayService(
236-
mockFactoryResolver, mockApplicationRef, mockInjector, mockAnimationBuilder, mockDocument, mockNgZone, mockPlatformUtil);
193+
let mockElement: any;
194+
let mockElementRef: any;
195+
let mockFactoryResolver: any;
196+
let mockApplicationRef: any;
197+
let mockInjector: any;
198+
let mockAnimationBuilder: any;
199+
let mockDocument: any;
200+
let mockNgZone: any;
201+
let mockPlatformUtil: any;
202+
let overlay: IgxOverlayService;
203+
beforeEach(() => {
204+
mockElement = {
205+
style: { visibility: '', cursor: '', transitionDuration: '' },
206+
classList: { add: () => { }, remove: () => { } },
207+
appendChild: () => { },
208+
removeChild: () => { },
209+
addEventListener: (type: string, listener: (this: HTMLElement, ev: MouseEvent) => any) => { },
210+
removeEventListener: (type: string, listener: (this: HTMLElement, ev: MouseEvent) => any) => { },
211+
getBoundingClientRect: () => ({ width: 10, height: 10 }),
212+
insertBefore: (newChild: HTMLDivElement, refChild: Node) => { },
213+
contains: () => { }
214+
};
215+
mockElement.parent = mockElement;
216+
mockElement.parentElement = mockElement;
217+
mockElementRef = { nativeElement: mockElement };
218+
mockFactoryResolver = {
219+
resolveComponentFactory: (c: any) => {
220+
return {
221+
create: (i: any) => {
222+
return {
223+
hostView: '',
224+
location: mockElementRef,
225+
changeDetectorRef: { detectChanges: () => { } },
226+
destroy: () => { }
227+
};
228+
}
229+
};
230+
}
231+
};
232+
mockApplicationRef = { attachView: (h: any) => { }, detachView: (h: any) => { } };
233+
mockInjector = {};
234+
mockAnimationBuilder = {};
235+
mockDocument = {
236+
body: mockElement,
237+
defaultView: mockElement,
238+
createElement: () => mockElement,
239+
appendChild: () => { },
240+
addEventListener: (type: string, listener: (this: HTMLElement, ev: MouseEvent) => any) => { },
241+
removeEventListener: (type: string, listener: (this: HTMLElement, ev: MouseEvent) => any) => { }
242+
};
243+
mockNgZone = {};
244+
mockPlatformUtil = { isIOS: false };
245+
246+
overlay = new IgxOverlayService(
247+
mockFactoryResolver, mockApplicationRef, mockInjector, mockAnimationBuilder, mockDocument, mockNgZone, mockPlatformUtil);
248+
});
237249

238250
it('Should set cursor to pointer on iOS', () => {
239251
mockPlatformUtil.isIOS = true;

0 commit comments

Comments
 (0)