Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import { NgModule } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { MyButtonComponent } from './mybutton.component';
  4. import { Router } from '@angular/router';
  5. @NgModule({
  6. imports: [
  7. CommonModule,
  8. ],
  9. declarations: [
  10. MyButtonComponent,
  11. ],
  12. exports: [
  13. MyButtonComponent,
  14. ],
  15. providers: [
  16. Router,
  17. ]
  18. })
  19. export class MyButtonModule { }
  20.  
  21. import { TestBed, ComponentFixture } from '@angular/core/testing';
  22. import { MyButtonModule } from './viewer-button.module';
  23. import { RouterTestingModule } from '@angular/router/testing';
  24.  
  25. // Tests Begining
  26. describe('ViewerButtonComponent', () => {
  27. let component: MyButtonComponent;
  28. let fixture: ComponentFixture<MyButtonComponent>;
  29.  
  30. beforeEach(() => {
  31. TestBed.configureTestingModule({
  32. imports: [
  33. ViewerButtonModule,
  34. RouterTestingModule.withRoutes([]),
  35. ],
  36. })
  37. .compileComponents();
  38.  
  39. fixture = TestBed.createComponent(MyButtonComponent);
  40. component = fixture.componentInstance;
  41. fixture.detectChanges();
  42.  
  43. });
  44.  
  45. it('#should create the component', () => {
  46. expect(component).toBeTruthy(' fail at creation');
  47. });
  48. });
  49.  
  50. beforeEach(() => {
  51. TestBed.configureTestingModule({
  52. imports: [
  53. // my childs component module
  54. MyChildComponentModule1,
  55. MyChildComponentModule2,
  56. ...
  57. MyChildComponentModuleX,
  58.  
  59. //the modules that mock what needed (or use custom mock in the providers part)
  60. RouterTestingModule,
  61. HttpClientTestingModule,
  62. ....
  63. SomethingTestingModule
  64. ],
  65. })
  66. .compileComponents();
  67.  
  68. fixture = TestBed.createComponent(MyButtonComponent);
  69. component = fixture.componentInstance;
  70. fixture.detectChanges();
  71.  
  72. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement