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 { 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) {
|
const event = dom.createEvent('CustomEvent');
|
||||||
win.CustomEvent = function(name: string, params: any) {
|
event.initCustomEvent(name, false, false, params.detail);
|
||||||
console.log('"hkljhlkhljkhljk');
|
return event;
|
||||||
const event = dom.createEvent('CustomEvent');
|
});
|
||||||
event.initCustomEvent(name, false, false, params.detail);
|
|
||||||
return event;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function mockView(component ?: any, data ?: any) {
|
function mockView(component ?: any, data ?: any) {
|
||||||
if (!component) {
|
if (!component) {
|
||||||
|
@ -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();
|
||||||
|
Reference in New Issue
Block a user