Skip to content

Commit

Permalink
fix(a19): respecting default standalone flag since angular 19
Browse files Browse the repository at this point in the history
Added standalone false as default for mock-render and updated isStandalone method to handle angular 19+ default standalone behavior for components.
  • Loading branch information
re-alam committed Nov 29, 2024
1 parent cad1d0e commit aa2b371
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
33 changes: 33 additions & 0 deletions libs/ng-mocks/src/lib/common/func.is-standalone.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Component, VERSION } from '@angular/core';

import { isStandalone } from './func.is-standalone';

@Component({
selector: 'standalone',
template: `<div>
<h1>Angular 19 standalone</h1>
</div>`,
})
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();
});
});
});
10 changes: 9 additions & 1 deletion libs/ng-mocks/src/lib/common/func.is-standalone.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { VERSION } from '@angular/core';

import collectDeclarations from '../resolve/collect-declarations';

import { getNgType } from './func.get-ng-type';
Expand All @@ -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;
}
1 change: 1 addition & 0 deletions libs/ng-mocks/src/lib/mock-render/func.create-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default (
selector: 'mock-render',
template: mockTemplate,
viewProviders: flags.viewProviders,
standalone: false,
};

ctor = generateWrapperComponent({ ...meta, bindings, options });
Expand Down

0 comments on commit aa2b371

Please sign in to comment.