测试时如何修复 ngrx 存储抛出错误?
How to fix ngrx store throwing error while testing?
我正在使用 ngrx/store 来管理我的应用程序的状态。
我正在使用 jest & jest-marbles 来测试应用程序。
但是在进行测试时,我无法 运行 正确地测试套件。
我在 运行 使用 ngrx/store/testing 进行测试时遇到以下错误。
我该如何纠正这个错误?
我检查了路径
'D:\my-app\node_modules\@ngrx\store\bundles\store-testing.umd.js'.
此文件已存在。但是测试仍然吐出这个错误。
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)
我该如何解决这个问题?
以下是我的测试设置:
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();
});
});
我刚刚试用了几个其他版本。 &错误是我使用的最新版本。
问题已解决。
我正在使用 ngrx/store 来管理我的应用程序的状态。
我正在使用 jest & jest-marbles 来测试应用程序。 但是在进行测试时,我无法 运行 正确地测试套件。
我在 运行 使用 ngrx/store/testing 进行测试时遇到以下错误。
我该如何纠正这个错误?
我检查了路径
'D:\my-app\node_modules\@ngrx\store\bundles\store-testing.umd.js'.
此文件已存在。但是测试仍然吐出这个错误。
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)
我该如何解决这个问题?
以下是我的测试设置:
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();
});
});
我刚刚试用了几个其他版本。 &错误是我使用的最新版本。
问题已解决。