mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
test(nav): tests for lifecycle events
This commit is contained in:
@ -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) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { NavDirection } from './nav-util';
|
||||
import { Animation, AnimationBuilder } from '../..';
|
||||
|
||||
export let MyCustomEvent = CustomEvent;
|
||||
|
||||
export async function transition(opts: AnimationOptions): Promise<Animation|void> {
|
||||
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<any> {
|
||||
if (el && (el as any).componentOnReady) {
|
||||
return (el as any).componentOnReady();
|
||||
|
Reference in New Issue
Block a user