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

lCleanup[useCaptureOrSubIdx] is not a function / view.disposables[i] is not a function #162

Closed
satanTime opened this issue Jul 11, 2020 · 5 comments · Fixed by #163
Closed

Comments

@satanTime
Copy link
Member

There's an interesting case that throws an error.

min project: ng-routing-test

The structure of the project should be like in the code sample above.

@satanTime
Copy link
Member Author

The issue is caused by (click)="..." in app.component.html, if to remove all of them there's no the issue.
For now I would assume that the problem is in angular itself, but still deeper investigation is required.

@satanTime
Copy link
Member Author

satanTime commented Jul 11, 2020

Here is app folder that can be used in e2e app.zip

@satanTime
Copy link
Member Author

satanTime commented Jul 11, 2020

The error is thrown only on 2+ execution of beforeEach, looks like there's a new cache inside of TestBed that should be reset in ngMocks.flushTestBed().

@satanTime
Copy link
Member Author

satanTime commented Jul 12, 2020

The min test to reproduce the issue.

import { Component, NgModule } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { BrowserModule } from '@angular/platform-browser';
import { MockBuilder, MockRender } from 'ng-mocks';

@Component({
  selector: 'app-root',
  template: `<a (click)="title = 'test'">click</a>`,
})
export class AppComponent {
  title = 'ng-routing-test';
}

@NgModule({
  bootstrap: [AppComponent],
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [],
})
export class AppModule {}

fdescribe('issue-162', () => {
  beforeEach(() => MockBuilder(AppComponent, AppModule));

  // triggers the error.
  afterEach(() => TestBed.resetTestingModule());

  it(`checks title`, () => {
    const fixture = MockRender(AppComponent);
    expect(fixture.point.componentInstance.title).toEqual('ng-routing-test');
  });
});

It only affects already existing components that belong to another module, if a new component is created at runtime then everything is fine and the error doesn't appear.

@satanTime satanTime changed the title lCleanup[useCaptureOrSubIdx] is not a function lCleanup[useCaptureOrSubIdx] is not a function / view.disposables[i] is not a function Jul 12, 2020
@satanTime
Copy link
Member Author

The problem is caused by mocked version of EventManager.addEventListener from BrowserModule.

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

Successfully merging a pull request may close this issue.

1 participant