Estoy haciendo los test con Karma v1.4.1 - connected y no pasa el del componente usuario por el router ->
import { Router } from '@angular/router';
@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styleUrls: ['./user.component.scss']
})
export class UserComponent implements OnInit {
public userList = [];
constructor(private service: DataProviderService, private router: Router) { }
ngOnInit() {
this.getUsers();
}
private getUsers = function () {
this.service.getUsers().subscribe(
data => {
this.userList = data;
}, err => {
console.log('err', err);
}
);
};
public detailUser(user: any) {
this.service.userContext = user;
this.router.navigate(['/detailComponent']);
};
Y su archivo .spect.ts le agregué el Router y el BrowserDynamicTestingModule (este lo leí de otro lado), el caso es que sigue sin funcionar.
import { UserComponent } from './user.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DataProviderService } from '../data-provider.service';
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { Router } from '@angular/router';
describe('UserComponent', () => {
let component: UserComponent;
let fixture: ComponentFixture<UserComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [UserComponent],
imports: [
HttpClientTestingModule,
// para el router
Router,
BrowserDynamicTestingModule
],
providers: [DataProviderService]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UserComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Chrome 74.0.3729 (Windows 10.0.0): Executed 5 of 5 (1 FAILED) (0.454 secs / 0.395 secs)
El fallo ->
UserComponent should create
Failed: Unexpected value 'Router' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.
Error: Unexpected value 'Router' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.
Expected undefined to be truthy.