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

Investigate Angular teardown #253

Closed
timdeschryver opened this issue Oct 13, 2021 · 8 comments
Closed

Investigate Angular teardown #253

timdeschryver opened this issue Oct 13, 2021 · 8 comments

Comments

@timdeschryver
Copy link
Member

beforeAll(() => {
  TestBed.resetTestEnvironment();
  TestBed.initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting(),
    {
      teardown: {
        destroyAfterEach: true, // <-- testing module teardown
      },
    },
  );
});

beforeEach(async () => {
  await render('<p>Anything here</p>');
  // (...)
});

Will become the default:

angular/angular#43353

@LayZeeDK
Copy link

LayZeeDK commented Oct 13, 2021

ModuleTeardownOptions are introduced by Angular 12.1. Additionally, generated values and default values change throughout Angular 12.2 and 13.0 as seen in the following table:

Angular version destroyAfterEach default value destroyAfterEach schematics-generated value
12.1 false N/A
12.2 false true
13.0 true N/A

When render(string) is used in a beforeEach hook and destroyAfterEach is true, an error like the following is thrown:

Error: Illegal state: Could not load the summary for directive WrapperComponent.

Other render signatures and other APIs might also be affected.

@LayZeeDK
Copy link

@timdeschryver
Copy link
Member Author

@LayZeeDK sorry to ping you here, but this reproduction should cause an error, right? I'm asking because I don't get the error.
Also, thanks for the extra info - I'll try Karma later this week.

@LayZeeDK
Copy link

I would think so, it's similar to what it looks like in my repo where I had the issue. Try putting the teardown in a beforeAll hook. I'll try to set up a minimal reproduction repo myself within the next week. This is the time and repo where I had the issue. Using Angular 12, Jest, Nx, Angular Testing Library 10 https://github.com/Energinet-DataHub/greenforce-frontend/blob/2e23092ab700beb3cc2f6cd112dd767276cd4c59/libs/ett/auth/feature-login/src/lib/ett-authentication-link.directive.spec.ts

@timdeschryver
Copy link
Member Author

Thanks @LayZeeDK I'll have a look at that spec later.
I also tried to add it to the beforeAll hook, but with the same result.

@timdeschryver
Copy link
Member Author

I just cloned that repo, and it seems fine to me, even when I set destroyAfterEach to true

@LayZeeDK
Copy link

Thanks for your support, @timdeschryver. I'm also unable to reproduce now. It must have been a local dependency issue.

You can close this issue.

@timdeschryver
Copy link
Member Author

No problem, thanks for your input!

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

2 participants