-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Destroy listeners aren't called in TestBed #18831
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
Labels
area: testing
Issues related to Angular testing features, such as TestBed
freq2: medium
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
state: has PR
type: bug/fix
Milestone
Comments
josephperrott
added a commit
to josephperrott/angular
that referenced
this issue
Jan 23, 2018
Closes angular#18831 BREAKING CHANGE: reset of TestingModule has changed from being done in a beforeEach to an afterEach.
3 tasks
josephperrott
added a commit
to josephperrott/angular
that referenced
this issue
Jan 24, 2018
Closes angular#18831 BREAKING CHANGE: reset of TestingModule has changed from being done in a beforeEach to an afterEach.
josephperrott
added a commit
to josephperrott/angular
that referenced
this issue
Jan 24, 2018
Closes angular#18831 BREAKING CHANGE: reset of TestingModule has changed from being done in a beforeEach to an afterEach.
crisbeto
added a commit
to crisbeto/angular
that referenced
this issue
Jun 12, 2021
This is something I ran into while working on a fix for the `TestBed` module teardown behavior for angular#18831. In the `RouterInitializer.appInitializer` we have a callback to the `LOCATION_INITIALIZED` which has to do some DI lookups. The problem is that if the module is destroyed before the location promise resolves, the `Injector.get` calls will fail. This is unlikely to happen in a real app, but it'll show up in unit tests once the test module teardown behavior is fixed.
crisbeto
added a commit
to crisbeto/angular
that referenced
this issue
Jun 12, 2021
This is something I ran into while working on a fix for the `TestBed` module teardown behavior for angular#18831. In the `RouterInitializer.appInitializer` we have a callback to the `LOCATION_INITIALIZED` which has to do some DI lookups. The problem is that if the module is destroyed before the location promise resolves, the `Injector.get` calls will fail. This is unlikely to happen in a real app, but it'll show up in unit tests once the test module teardown behavior is fixed.
crisbeto
added a commit
to crisbeto/angular
that referenced
this issue
Jun 13, 2021
We currently have two long-standing issues related to how `TestBed` tests are torn down: 1. The dynamically-created test module isn't going to be destroyed, preventing the `ngOnDestroy` hooks on providers from running and keeping the component `style` nodes in the DOM. 2. The test root elements aren't going to be removed from the DOM. Instead, they will be removed whenever another test component is created. By themselves, these issues are easy to resolve, but given how long they've been around, there are a lot of unit tests out there that depend on the broken behavior. These changes address the issues by introducing APIs that allow users to opt into the correct test teardown behavior either at the application level via `TestBed.initTestEnvironment` or the test suite level via `TestBed.configureTestingModule`. At the moment, the new teardown behavior is opt-in, but the idea is that we'll eventually make it opt-out before removing the configuration altogether. Fixes angular#18831.
crisbeto
added a commit
to crisbeto/angular
that referenced
this issue
Jun 13, 2021
We currently have two long-standing issues related to how `TestBed` tests are torn down: 1. The dynamically-created test module isn't going to be destroyed, preventing the `ngOnDestroy` hooks on providers from running and keeping the component `style` nodes in the DOM. 2. The test root elements aren't going to be removed from the DOM. Instead, they will be removed whenever another test component is created. By themselves, these issues are easy to resolve, but given how long they've been around, there are a lot of unit tests out there that depend on the broken behavior. These changes address the issues by introducing APIs that allow users to opt into the correct test teardown behavior either at the application level via `TestBed.initTestEnvironment` or the test suite level via `TestBed.configureTestingModule`. At the moment, the new teardown behavior is opt-in, but the idea is that we'll eventually make it opt-out before removing the configuration altogether. Fixes angular#18831.
crisbeto
added a commit
to crisbeto/angular
that referenced
this issue
Jun 13, 2021
We currently have two long-standing issues related to how `TestBed` tests are torn down: 1. The dynamically-created test module isn't going to be destroyed, preventing the `ngOnDestroy` hooks on providers from running and keeping the component `style` nodes in the DOM. 2. The test root elements aren't going to be removed from the DOM. Instead, they will be removed whenever another test component is created. By themselves, these issues are easy to resolve, but given how long they've been around, there are a lot of unit tests out there that depend on the broken behavior. These changes address the issues by introducing APIs that allow users to opt into the correct test teardown behavior either at the application level via `TestBed.initTestEnvironment` or the test suite level via `TestBed.configureTestingModule`. At the moment, the new teardown behavior is opt-in, but the idea is that we'll eventually make it opt-out before removing the configuration altogether. Fixes angular#18831.
crisbeto
added a commit
to crisbeto/angular
that referenced
this issue
Jun 15, 2021
We currently have two long-standing issues related to how `TestBed` tests are torn down: 1. The dynamically-created test module isn't going to be destroyed, preventing the `ngOnDestroy` hooks on providers from running and keeping the component `style` nodes in the DOM. 2. The test root elements aren't going to be removed from the DOM. Instead, they will be removed whenever another test component is created. By themselves, these issues are easy to resolve, but given how long they've been around, there are a lot of unit tests out there that depend on the broken behavior. These changes address the issues by introducing APIs that allow users to opt into the correct test teardown behavior either at the application level via `TestBed.initTestEnvironment` or the test suite level via `TestBed.configureTestingModule`. At the moment, the new teardown behavior is opt-in, but the idea is that we'll eventually make it opt-out before removing the configuration altogether. Fixes angular#18831.
crisbeto
added a commit
to crisbeto/angular
that referenced
this issue
Jun 17, 2021
We currently have two long-standing issues related to how `TestBed` tests are torn down: 1. The dynamically-created test module isn't going to be destroyed, preventing the `ngOnDestroy` hooks on providers from running and keeping the component `style` nodes in the DOM. 2. The test root elements aren't going to be removed from the DOM. Instead, they will be removed whenever another test component is created. By themselves, these issues are easy to resolve, but given how long they've been around, there are a lot of unit tests out there that depend on the broken behavior. These changes address the issues by introducing APIs that allow users to opt into the correct test teardown behavior either at the application level via `TestBed.initTestEnvironment` or the test suite level via `TestBed.configureTestingModule`. At the moment, the new teardown behavior is opt-in, but the idea is that we'll eventually make it opt-out before removing the configuration altogether. Fixes angular#18831.
dylhunn
pushed a commit
that referenced
this issue
Jun 17, 2021
…zed (#42560) This is something I ran into while working on a fix for the `TestBed` module teardown behavior for #18831. In the `RouterInitializer.appInitializer` we have a callback to the `LOCATION_INITIALIZED` which has to do some DI lookups. The problem is that if the module is destroyed before the location promise resolves, the `Injector.get` calls will fail. This is unlikely to happen in a real app, but it'll show up in unit tests once the test module teardown behavior is fixed. PR Close #42560
dylhunn
pushed a commit
that referenced
this issue
Jun 17, 2021
…zed (#42560) This is something I ran into while working on a fix for the `TestBed` module teardown behavior for #18831. In the `RouterInitializer.appInitializer` we have a callback to the `LOCATION_INITIALIZED` which has to do some DI lookups. The problem is that if the module is destroyed before the location promise resolves, the `Injector.get` calls will fail. This is unlikely to happen in a real app, but it'll show up in unit tests once the test module teardown behavior is fixed. PR Close #42560
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area: testing
Issues related to Angular testing features, such as TestBed
freq2: medium
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
state: has PR
type: bug/fix
I'm submitting a...
Current behavior
Destroy listeners that are registered on
PlatformRef
andNgModuleRef
withonDestroy
aren't called on test bed teardown.Expected behavior
It's expected that destroy listeners will be called automatically.
Minimal reproduction of the problem with instructions
A plunk:
What is the motivation / use case for changing the behavior?
Modules can have cleanup code that should be executed in order for them to function correctly in environments with multiple bootstraps (which TestBed tests are).
Environment
The text was updated successfully, but these errors were encountered: