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 4, 2023
1 parent 3f02148 commit 2c0a961
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 @@ -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';
Expand Down Expand Up @@ -60,12 +59,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 @@ -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);
});
Expand Down

0 comments on commit 2c0a961

Please sign in to comment.