Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What causes "Cannot configure the test module when the test module has already been instantiated"?

here is my test :

describe('ValueService', () => {

  it('#getValue should return real value', () => {
    expect(true).toBeTruthy();
  });
});

And I have this error :

Failed: Cannot configure the test module when the test module has already been instantiated. Make sure you are not using inject before R3TestBed.configureTestingModule. Error: Cannot configure the test module when the test module has already been instantiated. Make sure you are not using inject before R3TestBed.configureTestingModule.

like image 211
Saroste Avatar asked Dec 06 '25 04:12

Saroste


1 Answers

Please note that you may experience this error if the following conditions are true, even if you properly have your TestBed.configureTestingModule inside a describe:

  1. Your project is on Angular 13+
  2. You are using NgRx
  3. You are using provideMockStore in your test.

This issue is discussed here.

The fix is to add teardown: { destroyAfterEach: false } to your module configuration.

like image 96
Sameera Avatar answered Dec 08 '25 17:12

Sameera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!