Hello I am writing Unit test cases as below:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Injectable, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { By, BrowserModule } from '@angular/platform-browser';
import { MockBackend } from '@angular/http/testing';
import {Component, Directive, ChangeDetectorRef, Renderer2} from '@angular/core';
import { NgbModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
import {showallResult} from './showall.component';
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
import {SearchService} from '@backbase/commons';
import {ItemModel} from '@backbase/foundation-ang/core';
import { XHRBackend } from '@angular/http/src/backends/xhr_backend';
import { Subject, Observable } from 'rxjs';
import { mineModule} from 'libs/mine-portfolio/src/common.module';
class ItemModelStub {
public mockValue = new Subject<string>();
public property() {
return this.mockValue as Observable<string>;
}
}
fdescribe('showallResult', () => {
let fixture;
let component: any;
let itemModelStub;
beforeEach(() => {
const searchServiceStub = [{
"lastPrice": {
"currency": "EUR",
"price": 123425.63,
"date": "2019-12-27T09:05:28.368Z"
},
}]
itemModelStub = new ItemModelStub()
const changeDetectorRefStub = { markForCheck: () => ({}) };
TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
declarations:[],
providers: [
{ proivide: SearchService, useValue:searchServiceStub},
{ provide: ItemModel,useValue: itemModelStub },
{ provide: ChangeDetectorRef,useValue: changeDetectorRefStub },
],
imports : [mineModule,BrowserModule, NgbModule.forRoot()],
}).compileComponents();
fixture = TestBed.createComponent(showallResult);
component = fixture.componentInstance;
fixture.detectChanges();
});
I am getting error as below :
Error: Invalid provider for the NgModule 'DynamicTestModule' - only instances of Provider and Type are allowed, got: [?[object Object]?, ...]
this is probably because of this line:
{ proivide: SearchService, useValue:searchServiceStub},
Can anyone please help me in this.