diff --git a/libs/ng-mocks/src/lib/common/func.is-standalone.spec.ts b/libs/ng-mocks/src/lib/common/func.is-standalone.spec.ts new file mode 100644 index 0000000000..c59e2c09af --- /dev/null +++ b/libs/ng-mocks/src/lib/common/func.is-standalone.spec.ts @@ -0,0 +1,33 @@ +import { Component, VERSION } from '@angular/core'; + +import { isStandalone } from './func.is-standalone'; + +@Component({ + selector: 'standalone', + template: `
+

Angular 19 standalone

+
`, +}) +class StandaloneComponent {} + +describe('func.is-standalone', () => { + describe('Angular Angular 19+ specific tests', () => { + let originalVersion: { major: string }; + const setVersionMajor = (major: number) => { + Object.assign(VERSION, { major: major.toString() }); + }; + + beforeAll(() => { + originalVersion = { ...VERSION }; + }); + + afterEach(() => { + Object.assign(VERSION, originalVersion); + }); + + it('should return true when standalone is undefined', () => { + setVersionMajor(19); + expect(isStandalone(StandaloneComponent)).toBeTruthy(); + }); + }); +}); diff --git a/libs/ng-mocks/src/lib/common/func.is-standalone.ts b/libs/ng-mocks/src/lib/common/func.is-standalone.ts index 621d1415b9..f600d5d225 100644 --- a/libs/ng-mocks/src/lib/common/func.is-standalone.ts +++ b/libs/ng-mocks/src/lib/common/func.is-standalone.ts @@ -1,3 +1,5 @@ +import { VERSION } from '@angular/core'; + import collectDeclarations from '../resolve/collect-declarations'; import { getNgType } from './func.get-ng-type'; @@ -11,5 +13,11 @@ export function isStandalone(declaration: any): boolean { return false; } - return collectDeclarations(declaration)[type].standalone === true; + // Handle Angular 19+ default standalone behavior + const declarations = collectDeclarations(declaration); + if (Number(VERSION.major) >= 19 && type !== 'NgModule' && declarations[type].standalone === undefined) { + return true; + } + + return declarations[type].standalone === true; } diff --git a/libs/ng-mocks/src/lib/mock-render/func.create-wrapper.ts b/libs/ng-mocks/src/lib/mock-render/func.create-wrapper.ts index fddb8e5927..601b523c32 100644 --- a/libs/ng-mocks/src/lib/mock-render/func.create-wrapper.ts +++ b/libs/ng-mocks/src/lib/mock-render/func.create-wrapper.ts @@ -140,6 +140,7 @@ export default ( selector: 'mock-render', template: mockTemplate, viewProviders: flags.viewProviders, + standalone: false, }; ctor = generateWrapperComponent({ ...meta, bindings, options });