test(nav): tests for lifecycle events

This commit is contained in:
Manu Mtz.-Almeida
2018-03-20 16:48:20 +01:00
parent 06ad60ea0c
commit a73c461ed4
2 changed files with 13 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import { AnimationControllerImpl } from '../../animation-controller/animation-co
import { createConfigController } from '../../../global/config-controller'; import { createConfigController } from '../../../global/config-controller';
import { NavDirection, NavOptions, ViewState } from '../nav-util'; import { NavDirection, NavOptions, ViewState } from '../nav-util';
import { MyCustomEvent, mockLifecycle } from '../transition';
describe('NavController', () => { describe('NavController', () => {
@ -1074,15 +1075,11 @@ const MockView5 = 'mock-view5';
const dom = mockDocument(); const dom = mockDocument();
const win = global as any; mockLifecycle(function(name: string, params: any) {
if (!win.CustomEvent) {
win.CustomEvent = function(name: string, params: any) {
console.log('"hkljhlkhljkhljk');
const event = dom.createEvent('CustomEvent'); const event = dom.createEvent('CustomEvent');
event.initCustomEvent(name, false, false, params.detail); event.initCustomEvent(name, false, false, params.detail);
return event; return event;
}; });
}
function mockView(component ?: any, data ?: any) { function mockView(component ?: any, data ?: any) {
if (!component) { if (!component) {

View File

@ -1,6 +1,8 @@
import { NavDirection } from './nav-util'; import { NavDirection } from './nav-util';
import { Animation, AnimationBuilder } from '../..'; import { Animation, AnimationBuilder } from '../..';
export let MyCustomEvent = CustomEvent;
export async function transition(opts: AnimationOptions): Promise<Animation|void> { export async function transition(opts: AnimationOptions): Promise<Animation|void> {
const enteringEl = opts.enteringEl; const enteringEl = opts.enteringEl;
const leavingEl = opts.leavingEl; const leavingEl = opts.leavingEl;
@ -130,7 +132,7 @@ function setZIndex(enteringEl: HTMLElement, leavingEl: HTMLElement, direction: N
export function lifecycle(el: HTMLElement, lifecycle: ViewLifecycle) { export function lifecycle(el: HTMLElement, lifecycle: ViewLifecycle) {
if (el) { if (el) {
const event = new CustomEvent(lifecycle, { const event = new MyCustomEvent(lifecycle, {
bubbles: false, bubbles: false,
cancelable: 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<any> { function shallowReady(el: Element): Promise<any> {
if (el && (el as any).componentOnReady) { if (el && (el as any).componentOnReady) {
return (el as any).componentOnReady(); return (el as any).componentOnReady();