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

9.6.1 breaks tests with ngrx #142

Closed
vokeit-gschuster opened this issue Jun 18, 2020 · 9 comments · Fixed by #143
Closed

9.6.1 breaks tests with ngrx #142

vokeit-gschuster opened this issue Jun 18, 2020 · 9 comments · Fixed by #143
Assignees
Labels
bug Something isn't working
Milestone

Comments

@vokeit-gschuster
Copy link

vokeit-gschuster commented Jun 18, 2020

We upgraded ng-mocks to 9.6.1 today and several (about 10 of ~700) tests break because of ngrx missing injection tokens:

NullInjectorError: R3InjectorError(DynamicTestModule)[StoreFeatureModule -> InjectionToken @ngrx/store Internal Store Features -> InjectionToken @ngrx/store Internal Store Features]:
          NullInjectorError: No provider for InjectionToken @ngrx/store Internal Store Features!
        error properties: Object({ originalStack: 'Error: NullInjectorError: No provider for InjectionToken @ngrx/store Internal Store Features!

These now failing tests work absolutely fine with 9.5.0, @ngrx/effects 9.2.0 and @ngrx/store 9.2.0.
I see that the Module mock has been totally refactored and as far as I can tell it now seems to sometimes miss the given imports of StoreModule.forRoot(), StoreModule.forFeature(), EffectsModule.forRoot() and EffectsModule.forFeature().

@satanTime
Copy link
Member

satanTime commented Jun 18, 2020

Hi,

thank you for the report.
might you provide an example of a failing test and how ng-mocks is used there?

I have tests with StoreModule.forRoot(), StoreModule.forFeature(), EffectsModule.forRoot() and EffectsModule.forFeature() too and, unfortunately, they don't show the issue.

@vokeit-gschuster
Copy link
Author

I'll see if I can extract such a test.

@satanTime
Copy link
Member

satanTime commented Jun 18, 2020

Thanks, I think if you should how TestBed is setup and how module imports / declarations look like it should be enough. Perhaps I'm missing something in my setup.

@vokeit-gschuster
Copy link
Author

Test for MyComponent (in MyModule) fails with mocked "MyOtherModule" that has ngrx integrated.

describe('MyComponent', () => {
  TestBed.configureTestingModule({
    imports: [
      MockModule(MyOtherModule),
      HttpClientTestingModule
    ],
    declarations: [
      MyComponent,
      MyOtherComponent
    ],
    providers: [
      provideMockStore<AppState>(getMockState())
    ]
  })
  .compileComponents();

  //...
});

@NgModule({
  imports: [
    CommonModule,
    StoreModule.forFeature('xyz', xyzReducer),
    EffectsModule.forFeature([XyzEffects])
  ],
  providers: [
    XyzService
  ],
  declarations: [
    XyzComponent
  ],
  exports: [
    XyzComponent
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class MyOtherModule { }

@satanTime
Copy link
Member

Thanks, I was able to reproduce the issue, working on the fix.

@satanTime
Copy link
Member

satanTime commented Jun 18, 2020

Hi, again, might you verify the fix? Simply unpack it and put under node_modules: ng-mocks.zip.

@satanTime satanTime self-assigned this Jun 19, 2020
@satanTime satanTime added this to the v.9.6.2 milestone Jun 19, 2020
@satanTime satanTime added the bug Something isn't working label Jun 19, 2020
@vokeit-gschuster
Copy link
Author

Yes, fixed these problems.
I only have one test left that doesn't work because a form click on a radio box is not registered, don't know if that has something to do with ng-mocks.
If I find that it is caused by ng-mocks I'll open a new ticket.

Thanks for your quick fix!

@satanTime
Copy link
Member

Cool, the fix will be released on Sunday. About the form - might you share the test and the template of its component?

@satanTime
Copy link
Member

Hi there, 9.6.2 has been released. Please let me know how it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants