fix(ivy): R3TestBed should clean up registered modules after each test (#32872)

PR Close #32872
This commit is contained in:
Andrew Scott
2019-09-26 17:03:29 -07:00
committed by atscott
parent 53b32f17b3
commit 475e36abb5
4 changed files with 23 additions and 4 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Compiler, Component, Directive, ErrorHandler, Inject, Injectable, InjectionToken, Input, ModuleWithProviders, NgModule, Optional, Pipe, ɵsetClassMetadata as setClassMetadata, ɵɵdefineComponent as defineComponent, ɵɵdefineNgModule as defineNgModule, ɵɵtext as text} from '@angular/core';
import {Compiler, Component, Directive, ErrorHandler, Inject, Injectable, InjectionToken, Input, ModuleWithProviders, NgModule, Optional, Pipe, getModuleFactory, ɵsetClassMetadata as setClassMetadata, ɵɵdefineComponent as defineComponent, ɵɵdefineNgModule as defineNgModule, ɵɵtext as text} from '@angular/core';
import {TestBed, getTestBed} from '@angular/core/testing/src/test_bed';
import {By} from '@angular/platform-browser';
import {expect} from '@angular/platform-browser/testing/src/matchers';
@ -730,4 +730,17 @@ describe('TestBed', () => {
.toEqual(originalResolver);
});
});
onlyInIvy('Ivy module registration happens when NgModuleFactory is created')
.it('cleans up registered modules', async() => {
@NgModule({id: 'my_module'})
class MyModule {
}
expect(() => getModuleFactory('my_module')).toThrowError();
await TestBed.inject(Compiler).compileModuleAsync(MyModule);
expect(() => getModuleFactory('my_module')).not.toThrowError();
TestBed.resetTestingModule();
expect(() => getModuleFactory('my_module')).toThrowError();
});
});