diff --git a/core/src/components/nav/test/nav-controller.spec.ts b/core/src/components/nav/test/nav-controller.spec.ts index cf9c3773e8..875e01600a 100644 --- a/core/src/components/nav/test/nav-controller.spec.ts +++ b/core/src/components/nav/test/nav-controller.spec.ts @@ -5,6 +5,7 @@ import { AnimationControllerImpl } from '../../animation-controller/animation-co import { createConfigController } from '../../../global/config-controller'; import { NavDirection, NavOptions, ViewState } from '../nav-util'; +import { MyCustomEvent, mockLifecycle } from '../transition'; describe('NavController', () => { @@ -1074,15 +1075,11 @@ const MockView5 = 'mock-view5'; const dom = mockDocument(); -const win = global as any; -if (!win.CustomEvent) { - win.CustomEvent = function(name: string, params: any) { - console.log('"hkljhlkhljkhljk'); - const event = dom.createEvent('CustomEvent'); - event.initCustomEvent(name, false, false, params.detail); - return event; - }; -} +mockLifecycle(function(name: string, params: any) { + const event = dom.createEvent('CustomEvent'); + event.initCustomEvent(name, false, false, params.detail); + return event; +}); function mockView(component ?: any, data ?: any) { if (!component) { diff --git a/core/src/components/nav/transition.ts b/core/src/components/nav/transition.ts index 042dff75cb..5074b606b2 100644 --- a/core/src/components/nav/transition.ts +++ b/core/src/components/nav/transition.ts @@ -1,6 +1,8 @@ import { NavDirection } from './nav-util'; import { Animation, AnimationBuilder } from '../..'; +export let MyCustomEvent = CustomEvent; + export async function transition(opts: AnimationOptions): Promise { const enteringEl = opts.enteringEl; const leavingEl = opts.leavingEl; @@ -130,7 +132,7 @@ function setZIndex(enteringEl: HTMLElement, leavingEl: HTMLElement, direction: N export function lifecycle(el: HTMLElement, lifecycle: ViewLifecycle) { if (el) { - const event = new CustomEvent(lifecycle, { + const event = new MyCustomEvent(lifecycle, { bubbles: false, cancelable: false }); @@ -138,6 +140,10 @@ export function lifecycle(el: HTMLElement, lifecycle: ViewLifecycle) { } } +export function mockLifecycle(fn: any) { + MyCustomEvent = fn; +} + function shallowReady(el: Element): Promise { if (el && (el as any).componentOnReady) { return (el as any).componentOnReady();