2017-04-26 50 views
0

離子在3「認購」的定義,使用ion-slides,你可能會遇到以下錯誤:離子測試幻燈片,無法讀取性能在initEvents

Failed: Cannot read property 'subscribe' of undefined 
    TypeError: Cannot read property 'subscribe' of undefined 
     at initEvents (http://localhost:9877webpack:///~/ionic-angular/components/slides/swiper/swiper-events.js:63:0 <- src/test.ts:128385:48) 
     at Slides._initSlides (http://localhost:9877webpack:///~/ionic-angular/components/slides/slides.js:815:0 <- src/test.ts:61766:127) 
     at SafeSubscriber._next (http://localhost:9877webpack:///~/ionic-angular/components/slides/slides.js:530:0 <- src/test.ts:61481:23) 
     at SafeSubscriber.__tryOrUnsub (http://localhost:9877webpack:///~/rxjs/Subscriber.js:234:0 <- src/test.ts:17652:16) 
     at SafeSubscriber.next (http://localhost:9877webpack:///~/rxjs/Subscriber.js:183:0 <- src/test.ts:17601:22) 
     at Subscriber._next (http://localhost:9877webpack:///~/rxjs/Subscriber.js:125:0 <- src/test.ts:17543:26) 
     at Subscriber.next (http://localhost:9877webpack:///~/rxjs/Subscriber.js:89:0 <- src/test.ts:17507:18) 
     at http://localhost:9877webpack:///~/rxjs/observable/PromiseObservable.js:66:0 <- src/test.ts:115833:36 
     at ZoneDelegate.invoke (http://localhost:9877webpack:///~/zone.js/dist/zone.js:365:0 <- src/polyfills.ts:1520:26) 
     at AsyncTestZoneSpec.onInvoke (http://localhost:9877webpack:///~/zone.js/dist/async-test.js:49:0 <- src/test.ts:118535:39) 
     at ProxyZoneSpec.onInvoke (http://localhost:9877webpack:///~/zone.js/dist/proxy.js:76:0 <- src/test.ts:119221:39) 
     at ZoneDelegate.invoke (http://localhost:9877webpack:///~/zone.js/dist/zone.js:364:0 <- src/polyfills.ts:1519:32) 
     at Object.onInvoke (http://localhost:9877webpack:///~/@angular/core/@angular/core.es5.js:4145:0 <- src/test.ts:6663:37) 
     at ZoneDelegate.invoke (http://localhost:9877webpack:///~/zone.js/dist/zone.js:364:0 <- src/polyfills.ts:1519:32) 
     at Zone.run (http://localhost:9877webpack:///~/zone.js/dist/zone.js:125:0 <- src/polyfills.ts:1280:43) 

此錯誤是由訂閱platform.resize線引起的,在這裏看到的離子回購:https://github.com/driftyco/ionic/blob/e1913211930a53e77a4d18b70f673fea9799be75/src/components/slides/swiper/swiper-events.ts#L87

回答

0

你需要做的是將此添加到您的Platform mock,所以Observable不會subscribe到你的模擬中未定義的東西。

get resize(): Observable<any> { 
    return Observable.of(true); 
    } 

這是我的完整平臺模擬器,以防萬一需要它。

import { Observable } from 'rxjs/Observable' 

export class PlatformMock { 
    public ready(): Promise<{String}> { 
    return new Promise((resolve) => { 
     resolve('READY'); 
    }); 
    } 

    public registerBackButtonAction(fn: Function, priority?: number): Function { 
    return (() => true); 
    } 

    public hasFocus(ele: HTMLElement): boolean { 
    return true; 
    } 

    public doc(): HTMLDocument { 
    return document; 
    } 

    public is(): boolean { 
    return true; 
    } 

    public getElementComputedStyle(container: any): any { 
    return { 
     paddingLeft: '10', 
     paddingTop: '10', 
     paddingRight: '10', 
     paddingBottom: '10', 
    }; 
    } 

    public onResize(callback: any) { 
    return callback; 
    } 

    get resize(): Observable<any> { 
    return Observable.of(true); 
    } 

    public registerListener(ele: any, eventName: string, callback: any): Function { 
    return (() => true); 
    } 

    public win(): Window { 
    return window; 
    } 

    public raf(callback: any): number { 
    return 1; 
    } 

    public timeout(callback: any, timer: number): any { 
    return setTimeout(callback, timer); 
    } 

    public cancelTimeout(id: any) { 
    // do nothing 
    } 

    public getActiveElement(): any { 
    return document['activeElement']; 
    } 

}