Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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']);
- };
- 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)
- 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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement