Giter Site home page Giter Site logo

Comments (10)

satanTime avatar satanTime commented on June 14, 2024 1

The fix: #7492

from ng-mocks.

satanTime avatar satanTime commented on June 14, 2024

Hi @LPCmedia, could you create a min example with the failure?

I cannot reproduce on my side:

import { TestBed } from '@angular/core/testing';
import { MockBuilder } from 'ng-mocks';
import { provideMockStore } from '@ngrx/store/testing';
import { RouterTestingModule } from '@angular/router/testing';
import {provideTranslocoScope, TranslocoModule} from '@ngneat/transloco';
import {Component, InjectionToken} from "@angular/core";

const APT_INSTALL_API_CONFIGURATION = new InjectionToken('APT_INSTALL_API_CONFIGURATION');

@Component({
  selector: 'target',
  standalone: true,
  imports: [TranslocoModule],
  providers: [provideTranslocoScope({
    scope: 'core',
  })],
  template: `
    <nav *transloco="let t">
      <span>{{ t('core.test') }}</span>
    </nav>
  `,
})
class AppComponent {}

describe('AppComponent', () => {
  beforeEach(() => {
    return MockBuilder(AppComponent)
      .keep(AppComponent)
      .mock(TranslocoModule)
      .provide({
        provide: APT_INSTALL_API_CONFIGURATION,
        useValue: {
          host: 'foo.com',
          basePrefix: '/',
          port: 1,
        },
      })
  });

  beforeEach(() => TestBed.configureTestingModule({
      imports: [AppComponent, RouterTestingModule],
      providers: [provideMockStore({})]
    }).compileComponents()
  );

  it('should create the app', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app).toBeTruthy();
  });
});

from ng-mocks.

satanTime avatar satanTime commented on June 14, 2024

Also, could you check if this change solves the issue? ng-mocks.zip

from ng-mocks.

satanTime avatar satanTime commented on June 14, 2024

And this should help to understand which module is causing the issue: ng-mocks.zip

from ng-mocks.

LPCmedia avatar LPCmedia commented on June 14, 2024

I don't seem to have the issue with your second zip. The spec passes now and this is the output:

  ● Console
       
           console.log
             isExportedOnRoot _CommonModule
       
             at isExportedOnRoot (../../../node_modules/ng-mocks/index.js:5791:17)
       
           console.log
             init-ng-modules _CommonModule
       
             at ../../../node_modules/ng-mocks/index.js:5853:25
       
           console.log
             isExportedOnRoot _CommonModule
       
             at isExportedOnRoot (../../../node_modules/ng-mocks/index.js:5791:17)
             
             

Let me know if the repro is still needed for this bug ?

I may get to it tonight anyway as I am having unrelated issues with a NullInjectorError with an ngrx store following examples on the site with a renderFactory.

from ng-mocks.

satanTime avatar satanTime commented on June 14, 2024

aha.... interesting... it would be great to get an example with a failure on the current version.

I'll release the fix now, but the issue is I don't know how to cover it with tests.

from ng-mocks.

LPCmedia avatar LPCmedia commented on June 14, 2024

Fix works well thanks. And of course the repro is not reproducing....Its hard to reproduce everything in our private code base including the re-adding all the jest transforms and other fun configuration we need to add.

Let me know if you want to track under a separate issue. I will keep you posted should I find something, but I suspect that in the ngrx case we have some meta-reducer's at play that are may cause some strange behaviours.

      NullInjectorError: No provider for _Store!

      at NullInjector.get (../../../node_modules/@angular/core/fesm2022/core.mjs:5601:27)
      at R3Injector.slice (../../../node_modules/@angular/core/fesm2022/core.mjs:6044:33)
      at R3Injector.prop (../../../webpack:/ng-mocks/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts:378:33)
      at R3Injector.get (../../../webpack:/ng-mocks/libs/ng-mocks/src/lib/mock-service/helper.create-clone.ts:17:59)
      at R3Injector.slice (../../../node_modules/@angular/core/fesm2022/core.mjs:6044:33)
      at R3Injector.prop (../../../webpack:/ng-mocks/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts:378:33)
      at R3Injector.get (../../../webpack:/ng-mocks/libs/ng-mocks/src/lib/mock-service/helper.create-clone.ts:17:59)
      at _TestBedImpl.inject (../../../node_modules/@angular/core/fesm2022/testing.mjs:1844:62)
      at Function.inject (../../../node_modules/@angular/core/fesm2022/testing.mjs:1697:37)
      at src/app/shared/components/helpline-numbers/helpline-numbers.component.spec.ts:44:27
      at fakeAsyncFn (../../../node_modules/zone.js/bundles/zone-testing.umd.js:2083:34)
      at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone.umd.js:411:30)
      at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (../../../node_modules/zone.js/bundles/zone-testing.umd.js:300:43)
      at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone.umd.js:410:56)
      at Zone.Object.<anonymous>.Zone.run (../../../node_modules/zone.js/bundles/zone.umd.js:165:47)
      at Object.wrappedFunc (../../../node_modules/zone.js/bundles/zone-testing.umd.js:789:34)```

from ng-mocks.

satanTime avatar satanTime commented on June 14, 2024

Hi there,

unfortunately, without clear guidance how the issue appears, it's hard to track it.

With isExportedOnRoot _CommonModule, I can try to find a way to produce it.
However, for NullInjectorError: No provider for _Store! looks like a normal failure when injector tries to get a service which wasn't defined in TestBed.

I would suggest to change approach of calling MockBuilder and TestBed.configureTestingModule for the same test, because both of them have create independent contexts, and it can easily lead to missed injection.
The right way would be something like that:

  beforeEach(() => {
    return MockBuilder([AppComponent, RouterTestingModule], [TranslocoModule])
      .provide(provideMockStore({}))
      .provide({
        provide: APT_INSTALL_API_CONFIGURATION,
        useValue: {
          host: 'foo.com',
          basePrefix: '/',
          port: 1,
        },
      })
  });

instead of

  beforeEach(() => {
    return MockBuilder(AppComponent)
      .keep(AppComponent)
      .mock(TranslocoModule)
      .provide({
        provide: APT_INSTALL_API_CONFIGURATION,
        useValue: {
          host: 'foo.com',
          basePrefix: '/',
          port: 1,
        },
      })
  });

  beforeEach(() => TestBed.configureTestingModule({
      imports: [AppComponent, RouterTestingModule],
      providers: [provideMockStore({})]
    }).compileComponents()
  );

from ng-mocks.

LPCmedia avatar LPCmedia commented on June 14, 2024

Thanks, Im am closing this ticket.
FYI what was missing and made the rxjs test was the return statement on MockBuilder. 🤦

from ng-mocks.

satanTime avatar satanTime commented on June 14, 2024

Aha, that's good.

I'll keep it open to cover _CommonModule somehow in the future.

from ng-mocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.