I have been trying to debug this issue but I have had no success. I believe it's a lack of import of a nebular service or provider but I am not sure which one or where to find it.
my search.component.spec.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { NgxsModule, Store } from '@ngxs/store';
import { of } from 'rxjs';
import { SearchComponent } from './search.component';
import { NbAutocompleteModule, NbInputModule, NbOverlay, NbOverlayService, NbTriggerStrategyBuilderService, NbWindowService, NB_WINDOW } from '@nebular/theme';
import { InjectionToken } from '@angular/core';
describe('SearchComponent', () => {
let component: SearchComponent;
let fixture: ComponentFixture<SearchComponent>;
let store: Store;
let windowMock: NbWindowService = { } as any;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SearchComponent ],
imports: [NgxsModule.forRoot([]), HttpClientTestingModule, NbAutocompleteModule, NbInputModule ],
providers: [ NbWindowService, NbTriggerStrategyBuilderService,
{provide: NB_WINDOW, useClass: InjectionToken }
,
{ provide: NbOverlayService, useClass: NbOverlay }]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SearchComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
const store:Store = TestBed.inject(Store);
spyOn(store, 'select').and.returnValue(of(null));
spyOn(store, 'selectSnapshot').and.returnValue(null);
expect(component).toBeTruthy();
});
});
my search.component.html
<input #autoInput
nbInput
type="text"
(input)="onChange()"
placeholder="Search for companies"
[nbAutocomplete]="auto"
class= "search__input" />
<nb-autocomplete #auto (selectedChange)="onSelectionChange($event)">
<nb-option *ngFor="let option of filteredOptions$ | async" [value]="option">
{{ option }}
</nb-option>
</nb-autocomplete>
It's the bog-standard search component provided by nebular https://akveo.github.io/nebular/docs/components/autocomplete/overview#nbautocompletedirective
SearchComponent > should create
NullInjectorError: R3InjectorError(DynamicTestModule)[InjectionToken Window -> InjectionToken Window]:
NullInjectorError: No provider for InjectionToken Window!
error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'InjectionToken Window', 'InjectionToken Window' ] })
at <Jasmine>
at NullInjector.get (http://localhost:63217/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:915:1)
at R3Injector.get (http://localhost:63217/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:11081:1)
at R3Injector.get (http://localhost:63217/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:11081:1)
at NgModuleRef$1.get (http://localhost:63217/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:24198:1)
at Object.get (http://localhost:63217/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:22101:1)
at getOrCreateInjectable (http://localhost:63217/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:3921:1)
at Module.??directiveInject (http://localhost:63217/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:13752:1)
at NodeInjectorFactory.NbMenuComponent_Factory [as factory] (http://localhost:63217/_karma_webpack_/node_modules/@nebular/theme/__ivy_ngcc__/fesm2015/index.js:9693:120)
at getNodeInjectable (http://localhost:63217/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:4029:1)
at instantiateRootComponent (http://localhost:63217/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:7825:1)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…