diff --git a/packages/compiler/src/render3/r3_class_metadata_compiler.ts b/packages/compiler/src/render3/r3_class_metadata_compiler.ts index ac25865c6d5cda..9300678f789e29 100644 --- a/packages/compiler/src/render3/r3_class_metadata_compiler.ts +++ b/packages/compiler/src/render3/r3_class_metadata_compiler.ts @@ -75,7 +75,7 @@ export function compileClassMetadata(metadata: R3ClassMetadata): o.Expression { */ export function compileComponentClassMetadata( metadata: R3ClassMetadata, deferrableTypes: Map): o.Expression { - if (!deferrableTypes || deferrableTypes.size === 0) { + if (deferrableTypes.size === 0) { // If there are no deferrable symbols - just generate a regular `setClassMetadata` call. return compileClassMetadata(metadata); } diff --git a/packages/core/src/render3/jit/directive.ts b/packages/core/src/render3/jit/directive.ts index 747bf5200d310d..4d63659d9ea6f0 100644 --- a/packages/core/src/render3/jit/directive.ts +++ b/packages/core/src/render3/jit/directive.ts @@ -21,7 +21,6 @@ import {initNgDevMode} from '../../util/ng_dev_mode'; import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../definition'; import {NG_COMP_DEF, NG_DIR_DEF, NG_FACTORY_DEF} from '../fields'; import {ComponentDef, ComponentType, DirectiveDefList, PipeDefList} from '../interfaces/definition'; -import {getAsyncClassMetadata} from '../metadata'; import {stringifyForError} from '../util/stringify_utils'; import {angularCoreEnv} from './environment'; @@ -60,12 +59,6 @@ export function compileComponent(type: Type, metadata: Component): void { let ngComponentDef: ComponentDef|null = null; - if (getAsyncClassMetadata(type)) { - throw new Error( - `Component '${type.name}' has unresolved metadata. ` + - `Please call \`await TestBed.compileComponents()\` before running this test.`); - } - // Metadata may have resources which need to be resolved. maybeQueueResolutionOfComponentResources(type, metadata); diff --git a/packages/core/testing/src/test_bed_compiler.ts b/packages/core/testing/src/test_bed_compiler.ts index b38707cbc35a28..571b17722a25b3 100644 --- a/packages/core/testing/src/test_bed_compiler.ts +++ b/packages/core/testing/src/test_bed_compiler.ts @@ -382,11 +382,19 @@ export class TestBedCompiler { // Compile all queued components, directives, pipes. let needsAsyncResources = false; this.pendingComponents.forEach(declaration => { + if (getAsyncClassMetadata(declaration)) { + throw new Error( + `Component '${declaration.name}' has unresolved metadata. ` + + `Please call \`await TestBed.compileComponents()\` before running this test.`); + } + needsAsyncResources = needsAsyncResources || isComponentDefPendingResolution(declaration); + const metadata = this.resolvers.component.resolve(declaration); if (metadata === null) { throw invalidTypeError(declaration.name, 'Component'); } + this.maybeStoreNgDef(NG_COMP_DEF, declaration); compileComponent(declaration, metadata); });