lathonez / clicker

Ionic 2 + @angular/cli Seed Project : Angular2 + Typescript + Karma + Protractor + Travis
http://lathonez.com/2018/ionic-2-unit-testing/
MIT License
430 stars 137 forks source link

Problem with ion-slides #227

Closed rdiegoss closed 7 years ago

rdiegoss commented 7 years ago

Adding in any HTML tag

and run "npm test"

Error:

LoginPage: ✖ Should be create Login Page Chrome 56.0.2924 (Mac OS X 10.12.3) Error: Error in ./homePage class homePage - inline template:62:6 caused by: Cannot read property 'removeAttribute' of undefined TypeError: Cannot read property 'removeAttribute' of undefined at cleanupStyles (webpack:///~/ionic-angular/components/slides/swiper/swiper.js:797:0 <- src/test.ts:28038:16) at destroySwiper (webpack:///~/ionic-angular/components/slides/swiper/swiper.js:831:0 <- src/test.ts:28072:5) at Slides.ngOnDestroy (webpack:///~/ionic-angular/components/slides/slides.js:914:0 <- src/test.ts:44412:101) at Wrapper_Slides.ngOnDestroy (/IonicModule/Slides/wrapper.ngfactory.js:27:16) at CompiledTemplate.proxyViewClass.View_homePage0.destroyInternal (/DynamicTestModule/homePage/component.ngfactory.js:501:21) at CompiledTemplate.proxyViewClass.AppView.destroy (webpack:///~/@angular/core/src/linker/view.js:143:0 <- src/test.ts:82548:14) at CompiledTemplate.proxyViewClass.DebugAppView.destroy (webpack:///~/@angular/core/src/linker/view.js:371:0 <- src/test.ts:82776:38) at CompiledTemplate.proxyViewClass.View_homePage_Host0.destroyInternal (/DynamicTestModule/homePage/host.ngfactory.js:33:19) at CompiledTemplate.proxyViewClass.AppView.destroy (webpack:///~/@angular/core/src/linker/view.js:143:0 <- src/test.ts:82548:14) at CompiledTemplate.proxyViewClass.DebugAppView.destroy (webpack:///~/@angular/core/src/linker/view.js:371:0 <- src/test.ts:82776:38)

Ionic Framework Version: 2.0.0 Ionic CLI Version: 2.2.1 Ionic App Lib Version: 2.2.0 Ionic App Scripts Version: 1.0.0 ios-deploy version: 1.8.6 ios-sim version: 5.0.11 OS: macOS Sierra Node Version: v6.9.0 Xcode version: Xcode 8.1 Build version 8B62

lathonez commented 7 years ago

I am AFK this weekend.

My guess is that one of the mock classes we are using is missing a property that's meant to contain removeAttribute.

Have a look in cleanupStyles in the slides source code (referenced in your stack trace) to see what it is?

On Fri, 17 Feb 2017 at 07:06, Rodrigo Diego notifications@github.com wrote:

Adding in any HTML tag

and run "npm test"

Error:

LoginPage: ✖ Should be create Login Page Chrome 56.0.2924 (Mac OS X 10.12.3) Error: Error in ./homePage class homePage - inline template:62:6 caused by: Cannot read property 'removeAttribute' of undefined TypeError: Cannot read property 'removeAttribute' of undefined at cleanupStyles (webpack:////ionic-angular/components/slides/swiper/swiper.js:797:0 <- src/test.ts:28038:16) at destroySwiper (webpack:////ionic-angular/components/slides/swiper/swiper.js:831:0 <- src/test.ts:28072:5) at Slides.ngOnDestroy (webpack:////ionic-angular/components/slides/slides.js:914:0 <- src/test.ts:44412:101) at Wrapper_Slides.ngOnDestroy (/IonicModule/Slides/wrapper.ngfactory.js:27:16) at CompiledTemplate.proxyViewClass.View_homePage0.destroyInternal (/DynamicTestModule/homePage/component.ngfactory.js:501:21) at CompiledTemplate.proxyViewClass.AppView.destroy (webpack:////@angular/core/src/linker/view.js:143:0 <- src/test.ts:82548:14) at CompiledTemplate.proxyViewClass.DebugAppView.destroy (webpack:////@angular/core/src/linker/view.js:371:0 <- src/test.ts:82776:38) at CompiledTemplate.proxyViewClass.View_homePage_Host0.destroyInternal (/DynamicTestModule/homePage/host.ngfactory.js:33:19) at CompiledTemplate.proxyViewClass.AppView.destroy (webpack:////@angular/core/src/linker/view.js:143:0 <- src/test.ts:82548:14) at CompiledTemplate.proxyViewClass.DebugAppView.destroy (webpack:///~/@angular/core/src/linker/view.js:371:0 <- src/test.ts:82776:38)

Ionic Framework Version: 2.0.0 Ionic CLI Version: 2.2.1 Ionic App Lib Version: 2.2.0 Ionic App Scripts Version: 1.0.0 ios-deploy version: 1.8.6 ios-sim version: 5.0.11 OS: macOS Sierra Node Version: v6.9.0 Xcode version: Xcode 8.1 Build version 8B62

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lathonez/clicker/issues/227, or mute the thread https://github.com/notifications/unsubscribe-auth/AG5tSIShbZmIX_vopqjqO5VdNwy9yke8ks5rdKw-gaJpZM4MDe23 .

lathonez commented 7 years ago

Any luck?

rdiegoss commented 7 years ago

Don't resolve :(

But, I'm just testing methods in my page and ignore slides in tag....

Thx

lathonez commented 7 years ago

The error is coming from here in swiper.js:

/*=========================
  Translate/transition helpers
  ===========================*/
// Cleanup dynamic styles
function cleanupStyles(s) {
    // Container
    removeClass(s.container, s._classNames);
    s.container.removeAttribute('style');
lathonez commented 7 years ago

Ahah, there's actually an earlier error:

Uncaught TypeError: this._plt.timeout is not a function

Which is because we don't mock timeout in platformmock

lathonez commented 7 years ago

Fixing the above is trivial, but afterwards it seems that initSlides (which creates slides.component) is not called.

lathonez commented 7 years ago

Spent ages trying to figure out why the slides weren't being initialised, but it goes back to the first error:

        this._plt.timeout(function () {
            _this._initSlides();
        }, 300);

If we mock out the timeout function to do nothing.. then nothing will happen

lathonez commented 7 years ago

We were missing five functions from PlatformMock necessary for the Slides to work. If you update your copy of PlatformMock you should find they will test fine now.

rdiegoss commented 7 years ago

Thx, but this error continues....

HTML:

<div class="colgroup top-space">
    <ion-slides>

      <ion-slide>
        <img src""img>
      </ion-slide>

      <ion-slide>
        <img src""img>
      </ion-slide>

      <ion-slide>
        <img src""img>
      </ion-slide>

    </ion-slides>
  </div>

Plataform mock added 5 functions...

Error: Error in ./homePage class homePage - inline template:66:6 caused by: Cannot read property 'removeAttribute' of undefined TypeError: Cannot read property 'removeAttribute' of undefined at cleanupStyles (webpack:///~/ionic-angular/components/slides/swiper/swiper.js:797:0 <- src/test.ts:28898:16) at destroySwiper (webpack:///~/ionic-angular/components/slides/swiper/swiper.js:831:0 <- src/test.ts:28932:5) at Slides.ngOnDestroy (webpack:///~/ionic-angular/components/slides/slides.js:914:0 <- src/test.ts:45272:101) at Wrapper_Slides.ngOnDestroy (/IonicModule/Slides/wrapper.ngfactory.js:27:16) at CompiledTemplate.proxyViewClass.View_homePage0.destroyInternal (/DynamicTestModule/homePage/component.ngfactory.js:591:21) at CompiledTemplate.proxyViewClass.AppView.destroy (webpack:///~/@angular/core/src/linker/view.js:143:0 <- src/test.ts:82767:14) at CompiledTemplate.proxyViewClass.DebugAppView.destroy (webpack:///~/@angular/core/src/linker/view.js:371:0 <- src/test.ts:82995:38)

lathonez commented 7 years ago

You'll need to provide a repro case as I can no longer reproduce here against the latest version of clicker.

On Fri, 24 Feb 2017 at 23:59, Rodrigo Diego notifications@github.com wrote:

Sorry, but this error continues....

HTML:

Plataform mock added 5 functions...

Error: Error in ./homePage class homePage - inline template:66:6 caused by: Cannot read property 'removeAttribute' of undefined

TypeError: Cannot read property 'removeAttribute' of undefined

at cleanupStyles (webpack:////ionic-angular/components/slides/swiper/swiper.js:797:0 <- src/test.ts:28898:16) at destroySwiper (webpack:////ionic-angular/components/slides/swiper/swiper.js:831:0 <- src/test.ts:28932:5) at Slides.ngOnDestroy (webpack:////ionic-angular/components/slides/slides.js:914:0 <- src/test.ts:45272:101)

at Wrapper_Slides.ngOnDestroy (/IonicModule/Slides/wrapper.ngfactory.js:27:16)

at CompiledTemplate.proxyViewClass.View_homePage0.destroyInternal (/DynamicTestModule/homePage/component.ngfactory.js:591:21) at CompiledTemplate.proxyViewClass.AppView.destroy (webpack:////@angular/core/src/linker/view.js:143:0 <- src/test.ts:82767:14) at CompiledTemplate.proxyViewClass.DebugAppView.destroy (webpack:///~/@angular/core/src/linker/view.js:371:0 <- src/test.ts:82995:38)

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/lathonez/clicker/issues/227#issuecomment-282285368, or mute the thread https://github.com/notifications/unsubscribe-auth/AG5tSMD6MSYoFjXilxDA2Sjzlybo5Yocks5rftQugaJpZM4MDe23 .

recapix commented 7 years ago

Where namespace swipes are on ionic-angular ?

recapix commented 7 years ago

I Tried make this Mock but I don´t know the Slides namespace

export class SwiperMock{ public initSwiper(): void {}; public startAutoplay(): boolean { return true;}; public stopAutoplay(): void {}; public pauseAutoplay(): void {}; public updateAutoHeight(): void {}; public updateContainerSize(): void {}; public updateSlidesSize(): void {}; public currentSlidesPerView(): number {return 1}; public update(): void {}; public fixLoop(): void {}; public slideTo(): boolean {return true}; public onTransitionStart(): void {}; public onTransitionEnd(): void {}; public slideNext(): any { return {}}; public slidePrev(): any { return {}}; public slideReset(): boolean {return true;}; public disableTouchControl(): boolean {return true;}; public enableTouchControl(): boolean {return true;}; public destroySwiper(): void {};

lathonez commented 7 years ago

see https://github.com/driftyco/ionic-unit-testing-example/issues/22

franciscotln commented 7 years ago

I'm testing a page and facing the same problem 'Error during cleanup of component'. The problem is here components/slides/swiper/swipper.js:

function cleanupStyles (s) {
     s.container.removeAttribute('style');
    // Wrapper
    s._wrapper.removeAttribute('style');
}

this function is called inside another function destroySwiper() but the attributes container and _wrapper are missing so I get a TypeError by calling removeAttribute on undefined :-(

lathonez commented 7 years ago

Did you check out the linked issue?

https://github.com/driftyco/ionic-unit-testing-example/issues/22#issuecomment-291367781