Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { NgModule } from '@angular/core';
- import { CommonModule } from '@angular/common';
- import { MyButtonComponent } from './mybutton.component';
- import { Router } from '@angular/router';
- @NgModule({
- imports: [
- CommonModule,
- ],
- declarations: [
- MyButtonComponent,
- ],
- exports: [
- MyButtonComponent,
- ],
- providers: [
- Router,
- ]
- })
- export class MyButtonModule { }
- import { TestBed, ComponentFixture } from '@angular/core/testing';
- import { MyButtonModule } from './viewer-button.module';
- import { RouterTestingModule } from '@angular/router/testing';
- // Tests Begining
- describe('ViewerButtonComponent', () => {
- let component: MyButtonComponent;
- let fixture: ComponentFixture<MyButtonComponent>;
- beforeEach(() => {
- TestBed.configureTestingModule({
- imports: [
- ViewerButtonModule,
- RouterTestingModule.withRoutes([]),
- ],
- })
- .compileComponents();
- fixture = TestBed.createComponent(MyButtonComponent);
- component = fixture.componentInstance;
- fixture.detectChanges();
- });
- it('#should create the component', () => {
- expect(component).toBeTruthy(' fail at creation');
- });
- });
- beforeEach(() => {
- TestBed.configureTestingModule({
- imports: [
- // my childs component module
- MyChildComponentModule1,
- MyChildComponentModule2,
- ...
- MyChildComponentModuleX,
- //the modules that mock what needed (or use custom mock in the providers part)
- RouterTestingModule,
- HttpClientTestingModule,
- ....
- SomethingTestingModule
- ],
- })
- .compileComponents();
- fixture = TestBed.createComponent(MyButtonComponent);
- component = fixture.componentInstance;
- fixture.detectChanges();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement