Skip to content

Commit

Permalink
fixup! refactor(core): update TestBed to handle async component metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKushnir committed Aug 9, 2023
1 parent eac651c commit f3609ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function compileClassMetadata(metadata: R3ClassMetadata): o.Expression {
*/
export function compileComponentClassMetadata(
metadata: R3ClassMetadata, deferrableTypes: Map<string, string>): 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);
}
Expand Down
7 changes: 0 additions & 7 deletions packages/core/src/render3/jit/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../d
import {depsTracker, USE_RUNTIME_DEPS_TRACKER_FOR_JIT} from '../deps_tracker/deps_tracker';
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';
Expand Down Expand Up @@ -61,12 +60,6 @@ export function compileComponent(type: Type<any>, metadata: Component): void {

let ngComponentDef: ComponentDef<unknown>|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);

Expand Down
8 changes: 8 additions & 0 deletions packages/core/testing/src/test_bed_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,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);
});
Expand Down

0 comments on commit f3609ac

Please sign in to comment.