I have issue with error from topic. I'm using angular 7 version. There is my test: landing.component.spec.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LandingComponent } from './landing.component';
import { PegasPanelComponent } from '../pegas-panel/pegas-panel.component';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { TranslateServiceStub } from 'src/app/app-tests.spec';
import { routes } from '../user-access.routing';
describe('LandingComponent', () => {
let component: LandingComponent;
let fixture: ComponentFixture<LandingComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [LandingComponent, PegasPanelComponent, TranslateModule.forRoot()],
imports: [RouterTestingModule, routes],
providers: [{
provide: TranslateService,
useClass: TranslateServiceStub
}]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LandingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
landing.component.ts
import { Component, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'app-landing',
templateUrl: './landing.component.html',
styleUrls: ['./landing.component.scss']
})
export class LandingComponent implements OnInit {
constructor(private translateService: TranslateService) { translateService.setDefaultLang('en'); }
public ngOnInit() { }
}
And error:
HeadlessChrome 0.0.0 (Windows 10 0.0.0) LandingComponent should create FAILED
Failed: Unexpected value '[object Object]' imported by the module 'DynamicTestModule'
Error: Unexpected value '[object Object]' imported by the module 'DynamicTestModule'
I don't have any ideas how to fix it. Trying to add routing and move translateModule from declarations to imports (two answers i found) but this doesn't help.
Aucun commentaire:
Enregistrer un commentaire