diff --git a/src/serializers/ng-snapshot.ts b/src/serializers/ng-snapshot.ts index d6066a6fdc..93875f2a02 100644 --- a/src/serializers/ng-snapshot.ts +++ b/src/serializers/ng-snapshot.ts @@ -1,4 +1,4 @@ -import type { ComponentRef, DebugNode, Type, ɵCssSelectorList } from '@angular/core'; +import type { ComponentRef, DebugNode, Type, ɵCssSelectorList, ɵNgModuleType } from '@angular/core'; import type { ComponentFixture } from '@angular/core/testing'; import type { Colors } from 'pretty-format'; @@ -40,12 +40,14 @@ type Printer = (elementToSerialize: unknown) => string; const attributesToRemovePatterns = ['__ngContext__']; const ivyEnabled = (): boolean => { - // Should be required lazily, since it will throw an exception - // `Cannot resolve parameters...`. - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires - const { ɵivyEnabled } = require('@angular/core'); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { NgModule }: typeof import('@angular/core') = require('@angular/core'); - return ɵivyEnabled; + class IvyModule {} + NgModule()(IvyModule); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return !!(IvyModule as ɵNgModuleType).ɵmod; }; const print = (fixture: unknown, print: Printer, indent: Indent, opts: PluginOptions, colors: Colors): string => {