Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ngx-translate coverage in e2e #10752

Open
satanTime opened this issue Jan 12, 2025 · 5 comments
Open

Add ngx-translate coverage in e2e #10752

satanTime opened this issue Jan 12, 2025 · 5 comments

Comments

@satanTime
Copy link
Member

satanTime commented Jan 12, 2025

The fix isn't sufficient to support non-standalone components in third-party libraries like ngx-translate.
I applied the following fix to ensure support:
libs/ng-mocks/src/lib/mock/decorate-declaration.ts

@@ -46,6 +46,8 @@ export default <T extends Component & Directive>(
    },
  params: T,
): Component & Directive => {

+  const standalone = ((source as any).ɵcmp || (source as any).ɵdir || (source as any).ɵpipe)?.standalone;
  const hasResolver = ngMocksUniverse.config.has('mockNgDefResolver');
  if (!hasResolver) {
    ngMocksUniverse.config.set('mockNgDefResolver', new CoreDefStack());
@@ -61,10 +63,14 @@ export default <T extends Component & Directive>(
  if (meta.selector !== undefined) {
    options.selector = meta.selector;
  }

  if (meta.standalone !== undefined) {
    options.standalone = meta.standalone;
+  } else if (standalone !== undefined) {
+    options.standalone = standalone;
  }

Originally posted by @ytchenak in #10583 (comment)

@KernelFolla
Copy link

Hi, I'm trying to fix it too.

Have you noticed that pipes are now standalone by default?

I don't understand a thing - why not use the isStandalone method from @angular/core to check this? It would seem to be the most direct way to determine a component|directive|pipe standalone status.

@satanTime
Copy link
Member Author

I'll backport its implementation. The issue here is that this function doesn't exist in older angular versions and will break ng-mocks at project compilations.

@KernelFolla
Copy link

I've made this,
#10819

It's late and I'm not sure what I did - there's definitely an ugly part in there, but it seems to work for me. Maybe it can help you

@ytchenak
Copy link

@satanTime,
please see https://stackblitz.com/~/github.com/ytchenak/t1-ng-mocks as example.
I’m using @ngx-translate/core@15.0.0, which uses the non-standalone version to reproduce the issue.,

nx test t1-ng-mocks

 FAIL   t1-ng-mocks  src/app/app.component.spec.ts
  AppComponent
    × should create the app (146 ms)
  ● AppComponent › should create the app
    Unexpected "MockOf_TranslatePipe" found in the "declarations" array of the "MockOf_TranslateModule" NgModule, "MockOf_TranslatePipe" is marked as standalone and can't be declared in any NgModule - did you intend to import it instead (by adding it to the "imports" array)?
    Unexpected "MockOf_TranslateDirective" found in the "declarations" array of the "MockOf_TranslateModule" NgModule, "MockOf_TranslateDirective" is marked as standalone and can't be declared in any NgModule - did you intend to import it instead (by adding it to the "imports" array)?

@KernelFolla
Copy link

Hi @ytchenak @satanTime
fyi I've tested it with success using a package made from this PR #10826 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants