Нашел несколько похожих ошибок, но я не думаю, что они применимы.Они говорят о порядке компонентов, и я думаю, что я все перепробовал.
Я пишу новый модульный тест для существующей службы.Вот конструктор службы:
@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)
Как я уже говорил, я пытался упорядочить и сравнить с другими модульными тестами в моем проекте.Я не уверен, что делать дальше.