store: 🐞[BUG]: Unexpected value 'NgxsRootModule' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.

Description

Nx Workspace lib component testing

🔬 Minimal Reproduction

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { NgxsModule } from '@ngxs/store';

import { SignInComponent } from './sign-in.component';

describe('SignInComponent', () => {
  let component: SignInComponent;
  let fixture: ComponentFixture<SignInComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [SignInComponent],
      imports: [
        RouterTestingModule,
        NgxsModule.forRoot([], { developmentMode: true }),
      ],
    }).compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(SignInComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

🔥 Exception or Error

Unexpected value ‘NgxsRootModule’ imported by the module ‘DynamicTestModule’. Please add an @NgModule annotation.

Environment


Libs:
- @angular/core version: ^11.2.0
- @ngxs/store version: ^3.7.1


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 19 (6 by maintainers)

Most upvoted comments

Update: in this issue discussion it was mentioned that the problem might come from faulty or missing metadata by the Angular compiler. So I ran npx ngcc again and that fixed the issue for me!

Me too! I’m on Angular 13, npx ngcc seems to resolves the issue.

Me too! I’m on Angular 13, npx ngcc seems to resolves the issue.

Update: in this issue discussion it was mentioned that the problem might come from faulty or missing metadata by the Angular compiler. So I ran npx ngcc again and that fixed the issue for me!

Hi, thanks a lot. This fixed my issue too. But why did this work? I am on Angular and Nx version 14, Jest and @ngxs/store@3.7.5

I have same issue after Upgrading NX and Angular and NGXS to latest versions

@markwhitfeld can we drop support angular 9, 8, 7, 6?

there is a lot to be done since it’s not backward compatible, I don’t think I will have enough time for this, especially ngxs dependencies are set to version 9 atm.

@yadue hello, could you send PR with fix current bug, please?

@splincode from what I see _isAngularInTestMode currently checks for MockNgModuleResolver but ResourceProvider is being provided.

https://i.imgur.com/SxvhP2t.png related: https://github.com/angular/angular/issues/44629