Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test.spec > Cannot read property 'destroy' of undefined #217

Closed
1 task done
CosmoFruit opened this issue Oct 12, 2018 · 10 comments
Closed
1 task done

test.spec > Cannot read property 'destroy' of undefined #217

CosmoFruit opened this issue Oct 12, 2018 · 10 comments

Comments

@CosmoFruit
Copy link

CosmoFruit commented Oct 12, 2018

Bug Report or Feature Request (mark with an x)

  • bug report -> please search issues before submitting

OS and Version?

Ubuntu 18

Versions

"@angular/cli": "~7.0.0-rc.1",
"@ngx-progressbar/core": "^5.2.0",

Repro steps

App.component.html

<ng-progress color="red"></ng-progress>
<router-outlet></router-outlet>

App.component.spec.ts

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
NgProgressModule,
RouterTestingModule,
],
declarations: [
AppComponent,
],
}).compileComponents();
}));

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});

});

The log given by the failure

TypeError: Cannot read property 'destroy' of undefined
at NgProgressComponent.push../node_modules/@ngx-progressbar/core/fesm5/ngx-progressbar-core.js.NgProgressComponent.ngOnDestroy (http://localhost:9878/node_modules/@ngx-progressbar/core/fesm5/ngx-progressbar-core.js?:478:1)
at callProviderLifecycles (http://localhost:9878/node_modules/@angular/core/fesm5/core.js?:18506:1)
at callElementProvidersLifecycles (http://localhost:9878/node_modules/@angular/core/fesm5/core.js?:18474:1)
at callLifecycleHooksChildrenFirst (http://localhost:9878/node_modules/@angular/core/fesm5/core.js?:18464:1)
at destroyView (http://localhost:9878/node_modules/@angular/core/fesm5/core.js?:19526:1)
at callViewAction (http://localhost:9878/node_modules/@angular/core/fesm5/core.js?:19652:1)
at execComponentViewsAction (http://localhost:9878/node_modules/@angular/core/fesm5/core.js?:19574:1)
at destroyView (http://localhost:9878/node_modules/@angular/core/fesm5/core.js?:19525:1)
at callWithDebugContext (http://localhost:9878/node_modules/@angular/core/fesm5/core.js?:20285:1)
at Object.debugDestroyView [as destroyView] (http://localhost:9878/node_modules/@angular/core/fesm5/core.js?:19969:1)}

Desired functionality

how to right test component with ngProgressComponent? if i dont want mock it?

@MurhafSousli
Copy link
Owner

The library does not have test files yet!

@chendachao
Copy link

I encountered the same issue, have to use schemas: [NO_ERRORS_SCHEMA] to ignore the ng-progress tag as of now. Keep looking for some better solutions.

@bougnat12
Copy link

I encountered the same issue.

I patched the node_modules/@ngx-progressbar/core/fesm5/ngx-progressbar-core.js like this by adding a test before calling destroy() function:

    NgProgressComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        this._started.unsubscribe();
        this._completed.unsubscribe();
        if (this.progressRef instanceof NgProgressRef) {
          this.progressRef.destroy();
        }
    };

Hope that helps to correct this bug.

@nielswitte
Copy link

nielswitte commented Dec 31, 2018

I am having the same issue when running ng test for a component which uses the ng-progress component.

@meiordac
Copy link

meiordac commented Jan 8, 2019

having the same issue

@eleftherias
Copy link
Contributor

As a workaround you can add fixture.detectChanges() to either run before your tests or during your test.
The code from the original repro steps can be modified like this:

describe('AppComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        NgProgressModule,
        RouterTestingModule,
      ],
      declarations: [
        AppComponent,
      ],
    }).compileComponents();
  }));

  it('should create the app', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.debugElement.componentInstance;
    // This is necessary
    fixture.detectChanges();
    expect(app).toBeTruthy();
  });
});

@steve-todorov
Copy link

steve-todorov commented Jan 26, 2019

@MurhafSousli, it looks like @eleftherias's PR has fixed the issue for me (I've tried it by manually building it and replacing the installed package). Will you be releasing it soon? Our build has started failing in Jenkins because of this issue.

steve-todorov added a commit to strongbox/strongbox-web-ui that referenced this issue Jan 26, 2019
@steve-todorov
Copy link

ping... any updates? :)

@MurhafSousli
Copy link
Owner

Fixed in v5.3.2

@steve-todorov
Copy link

Many thanks! 🎆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants