Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import { Router } from '@angular/router';
  2.  
  3. @Component({
  4. selector: 'app-user',
  5. templateUrl: './user.component.html',
  6. styleUrls: ['./user.component.scss']
  7. })
  8. export class UserComponent implements OnInit {
  9. public userList = [];
  10. constructor(private service: DataProviderService, private router: Router) { }
  11.  
  12. ngOnInit() {
  13. this.getUsers();
  14. }
  15.  
  16. private getUsers = function () {
  17. this.service.getUsers().subscribe(
  18. data => {
  19. this.userList = data;
  20. }, err => {
  21. console.log('err', err);
  22. }
  23. );
  24. };
  25.  
  26. public detailUser(user: any) {
  27. this.service.userContext = user;
  28. this.router.navigate(['/detailComponent']);
  29. };
  30.  
  31. import { UserComponent } from './user.component';
  32. import { async, ComponentFixture, TestBed } from '@angular/core/testing';
  33. import { DataProviderService } from '../data-provider.service';
  34. import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
  35. import { HttpClientTestingModule } from '@angular/common/http/testing';
  36. import { Router } from '@angular/router';
  37.  
  38. describe('UserComponent', () => {
  39. let component: UserComponent;
  40. let fixture: ComponentFixture<UserComponent>;
  41.  
  42. beforeEach(async(() => {
  43. TestBed.configureTestingModule({
  44. declarations: [UserComponent],
  45. imports: [
  46. HttpClientTestingModule,
  47. // para el router
  48. Router,
  49. BrowserDynamicTestingModule
  50. ],
  51. providers: [DataProviderService]
  52. })
  53. .compileComponents();
  54. }));
  55.  
  56. beforeEach(() => {
  57. fixture = TestBed.createComponent(UserComponent);
  58. component = fixture.componentInstance;
  59. fixture.detectChanges();
  60. });
  61.  
  62. it('should create', () => {
  63. expect(component).toBeTruthy();
  64. });
  65. });
  66.  
  67. Chrome 74.0.3729 (Windows 10.0.0): Executed 5 of 5 (1 FAILED) (0.454 secs / 0.395 secs)
  68.  
  69. UserComponent should create
  70. Failed: Unexpected value 'Router' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.
  71.  
  72. Error: Unexpected value 'Router' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.
  73.  
  74. Expected undefined to be truthy.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement