|
9 | 9 | import {ResourceLoader} from '@angular/compiler';
|
10 | 10 | import {CompileMetadataResolver} from '@angular/compiler/src/metadata_resolver';
|
11 | 11 | import {MockResourceLoader} from '@angular/compiler/testing/src/resource_loader_mock';
|
12 |
| -import {Component, Directive, Injectable, NgModule, Pipe, Type} from '@angular/core'; |
| 12 | +import {Component, Directive, Injectable, NgModule, OnDestroy, Pipe, Type} from '@angular/core'; |
13 | 13 | import {TestBed, async, getTestBed} from '@angular/core/testing';
|
14 | 14 | import {expect} from '@angular/platform-browser/testing/src/matchers';
|
15 | 15 |
|
@@ -56,6 +56,10 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
56 | 56 | constructor(service: SomeService) {}
|
57 | 57 | }
|
58 | 58 |
|
| 59 | + @Component({template: ''}) |
| 60 | + class TestCompErrorOnDestroy implements OnDestroy { |
| 61 | + ngOnDestroy() {} |
| 62 | + } |
59 | 63 |
|
60 | 64 | function resetTestEnvironmentWithSummaries(summaries?: () => any[]) {
|
61 | 65 | const {platform, ngModule} = getTestBed();
|
@@ -207,6 +211,31 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
207 | 211 | .toThrowError('SomeModule was AOT compiled, so its metadata cannot be changed.');
|
208 | 212 | });
|
209 | 213 |
|
| 214 | + it('should return stack trace and component data on resetTestingModule when error is thrown', |
| 215 | + () => { |
| 216 | + resetTestEnvironmentWithSummaries(); |
| 217 | + |
| 218 | + const fixture = TestBed.configureTestingModule({declarations: [TestCompErrorOnDestroy]}) |
| 219 | + .createComponent<TestCompErrorOnDestroy>(TestCompErrorOnDestroy); |
| 220 | + |
| 221 | + const expectedError = 'Error from ngOnDestroy'; |
| 222 | + |
| 223 | + const component: TestCompErrorOnDestroy = fixture.componentInstance; |
| 224 | + |
| 225 | + spyOn(console, 'error'); |
| 226 | + spyOn(component, 'ngOnDestroy').and.throwError(expectedError); |
| 227 | + |
| 228 | + const expectedObject = { |
| 229 | + stacktrace: new Error(expectedError), |
| 230 | + component, |
| 231 | + }; |
| 232 | + |
| 233 | + TestBed.resetTestingModule(); |
| 234 | + |
| 235 | + expect(console.error) |
| 236 | + .toHaveBeenCalledWith('Error during cleanup of component', expectedObject); |
| 237 | + }); |
| 238 | + |
210 | 239 | it('should allow to add summaries via configureTestingModule', () => {
|
211 | 240 | resetTestEnvironmentWithSummaries();
|
212 | 241 |
|
|
0 commit comments