fix(ivy): check semantics of NgModule for consistency (#27604)
`NgModule` requires that `Component`s/`Directive`s/`Pipe`s are listed in declarations, and that each `Component`s/`Directive`s/`Pipe` is declared in exactly one `NgModule`. This change adds runtime checks to ensure that these sementics are true at runtime. There will need to be seperate set of checks for the AoT path of the codebase to verify that same set of semantics hold. Due to current design there does not seem to be an easy way to share the two checks because JIT deal with references where as AoT deals with AST nodes. PR Close #27604
This commit is contained in:
@ -195,9 +195,6 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
expect(injector.get(Service)).toBe(instance);
|
||||
});
|
||||
|
||||
it('throws an error when a token is not found',
|
||||
() => { expect(() => injector.get(ServiceTwo)).toThrow(); });
|
||||
|
||||
it('returns the default value if a provider isn\'t present',
|
||||
() => { expect(injector.get(ServiceTwo, null)).toBeNull(); });
|
||||
|
||||
@ -240,9 +237,6 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
expect(instance.dep).toBe(injector.get(Service));
|
||||
});
|
||||
|
||||
it('throws an error on circular deps',
|
||||
() => { expect(() => injector.get(CircularA)).toThrow(); });
|
||||
|
||||
it('allows injecting itself via INJECTOR',
|
||||
() => { expect(injector.get(INJECTOR)).toBe(injector); });
|
||||
|
||||
@ -287,4 +281,24 @@ describe('InjectorDef-based createInjector()', () => {
|
||||
injector = createInjector(ImportsNotAModule);
|
||||
expect(injector.get(ImportsNotAModule)).toBeDefined();
|
||||
});
|
||||
|
||||
describe('error handling', () => {
|
||||
it('throws an error when a token is not found',
|
||||
() => { expect(() => injector.get(ServiceTwo)).toThrow(); });
|
||||
|
||||
it('throws an error on circular deps',
|
||||
() => { expect(() => injector.get(CircularA)).toThrow(); });
|
||||
|
||||
it('should throw when it can\'t resolve all arguments', () => {
|
||||
class MissingArgumentType {
|
||||
constructor(missingType: any) {}
|
||||
}
|
||||
class ErrorModule {
|
||||
static ngInjectorDef =
|
||||
defineInjector({factory: () => new ErrorModule(), providers: [MissingArgumentType]});
|
||||
}
|
||||
expect(() => createInjector(ErrorModule).get(MissingArgumentType))
|
||||
.toThrowError('Can\'t resolve all parameters for MissingArgumentType: (?).');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user