How to fix ngrx store throwing error while testing?

心不动则不痛 提交于 2020-06-01 05:12:07

问题


I'm using ngrx/store for managing the state of my app.

I'm using jest & jest-marbles for testing the app. But while doing testing I'm not being able to run the test suite properly.

I'm getting the following error while running tests with ngrx/store/testing.

How can I rectify this error?

I've inspected the path

'D:\my-app\node_modules\@ngrx\store\bundles\store-testing.umd.js'.

This file already exists. But still the test is spitting this error.

    Could not find source file: 'D:\my-app\node_modules\@ngrx\store\bundles\store-testing.umd.js'.

      at getValidSourceFile (node_modules/typescript/lib/typescript.js:135637:29)
      at Object.getSyntacticDiagnostics (node_modules/typescript/lib/typescript.js:135851:52)
      at Object.diagnoseFn [as diagnose] (node_modules/ts-jest/dist/compiler/language-service.js:87:37)
      at TsJestTransformer.getCacheKey (node_modules/ts-jest/dist/ts-jest-transformer.js:122:32)
      at ScriptTransformer._getCacheKey (node_modules/@jest/transform/build/ScriptTransformer.js:259:23)
      at ScriptTransformer._getFileCachePath (node_modules/@jest/transform/build/ScriptTransformer.js:285:27)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:413:32)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:525:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:563:25)

How can I fix this?

The following is my test setup :

describe('ItemRowComponent', () =>
{
  let component: ItemRowComponent;
  let fixture: ComponentFixture<ItemRowComponent>;
  const initialState = INITIAL_STATE;
  // INITIAL STATE is getting imported from the reducer file.
  let store: MockStore<ActionsControlsState>;

  beforeEach(async(() =>
  {
    TestBed.configureTestingModule({
      declarations: [ItemRowComponent],
      providers: [
        provideMockStore({ initialState }),
      ],
    }).compileComponents();
  }));

  beforeEach(() =>
  {
    fixture = TestBed.createComponent(ItemRowComponent);
    component = fixture.componentInstance;
    store = TestBed.inject(MockStore);
    fixture.detectChanges();
  });

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

回答1:


I just tried out a couple of other versions. & the error was with the latest version which I've used.

The issue is resolved.



来源:https://stackoverflow.com/questions/61841325/how-to-fix-ngrx-store-throwing-error-while-testing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!