代码之家  ›  专栏  ›  技术社区  ›  Thom

错误:无法解析httpRequest的所有参数

  •  0
  • Thom  · 技术社区  · 7 年前

    发现了几个类似的错误,但我认为它们不适用。他们讨论了组件的顺序,我想我已经尝试了所有的方法。

    我正在为现有服务编写新的单元测试。以下是服务构造函数:

    @Injectable()
    export class CreateSpAuthorizationUtility {
        constructor(
            private dialogService: DialogService,
            private router: Router,
            private store: Store<AppStore>,
            private noteService: NoteService,
            private stepperService: StepperService
        ) {
        }
    }
    

    这是我写的单元测试:

    describe('Given a CreateSpAuthorizationUtility', () => {
    
        beforeEach(async(() => {
            TestBed.configureTestingModule({
                declarations: [
                ],
                imports: [
                    HttpClientTestingModule
                ],
                providers: [
                    AppConfig,
                    HttpRequest,
                    CreateSpAuthorizationUtility,
                    {provide: DialogService, useClass: MockDialogService},
                    {provide: NoteService, useClass: MockNoteService},
                    {provide: Router, useClass: MockRouter},
                    {provide: StepperService, useClass: StepperServiceMock},
                    {provide: Store, useClass: TestStore}
                ]
            });
        }));
    
        it('should build query params',
            inject([CreateSpAuthorizationUtility, HttpTestingController, AppConfig],
                fakeAsync( (service: CreateSpAuthorizationUtility,
                            mockBackend: HttpTestingController,
                            appConfig: AppConfig,
                            router: MockRouter,
                            store: TestStore<AppStore>,
                            dialogService: MockDialogService,
                            noteService: MockNoteService,
                            stepperService: StepperServiceMock)  => {
    
                    const prescreen: SpPrescreenSelectedValues = SP_PRESCREEN_SELECTED_VALUES_MOCK;
                    service.buildQueryParams(prescreen, false);
                })));
    });
    

    下面是MockNoteService:

    @Injectable()
    export class MockNoteService extends NoteService {
        public static NON_EXISTING_ID = 'nonExistingId';
    
        public getNoteDefinition(noteDefinitionVisibleId: string): Observable<NoteDefinition> {
            if (noteDefinitionVisibleId === MockNoteService.NON_EXISTING_ID) {
                return observableThrowError('Test');
            }
    
            return of({
                id: '',
                version: 0,
                name: '',
                description: '',
                attributeDefs: [],
                visibleId: '',
                userCreatable: false,
                instanceCopyable: false,
                definitionEditable: false,
                isSystem: false,
                bodyRequired: true
            });
        }
    }
    

    扩展了noteservice:

    export class NoteService extends BaseService {
        constructor(private http: HttpRequest, private appConfig: AppConfig, private store: Store<AppStore>) {
            super();
        }
    }
    

    当我运行它时,我得到以下错误:

    Error: Can't resolve all parameters for HttpRequest: (?, ?, ?, ?).
        at syntaxError (http://localhost:9876/node_modules/@angular/compiler/fesm5/compiler.js?:1021:1)
        at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getDependenciesMetadata (http://localhost:9876/node_modules/@angular/compiler/fesm5/compiler.js?:10922:1)
        at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getTypeMetadata (http://localhost:9876/node_modules/@angular/compiler/fesm5/compiler.js?:10815:1)
        at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getInjectableTypeMetadata (http://localhost:9876/node_modules/@angular/compiler/fesm5/compiler.js?:11037:1)
        at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getProviderMetadata (http://localhost:9876/node_modules/@angular/compiler/fesm5/compiler.js?:11046:1)
        at http://localhost:9876/node_modules/@angular/compiler/fesm5/compiler.js?:10984:1
        at Array.forEach (<anonymous>)
        at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getProvidersMetadata (http://localhost:9876/node_modules/@angular/compiler/fesm5/compiler.js?:10944:1)
        at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleMetadata (http://localhost:9876/node_modules/@angular/compiler/fesm5/compiler.js?:10663:53)
        at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._loadModules (http://localhost:9876/node_modules/@angular/compiler/fesm5/compiler.js?:23876:1)
    

    正如我所说,我已经尝试过在我的项目中排序并与其他单元测试进行比较。我不知道下一步该怎么办。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Thom    7 年前

    最后,我让mocknoteservice不再从noteservice扩展,这样我就没有继承链,这似乎解决了问题。

    谢谢你的帮助,布茨科夫斯基。

    推荐文章