import { ComponentFixture, TestBed } from '@angular/core/testing'; import { SomethingWentWrongComponent } from './something-went-wrong.component'; import {WindowService} from '../services/window.service'; import {ActivatedRoute} from '@angular/router'; import {of} from 'rxjs/internal/observable/of'; describe('SomethingWentWrongComponent', () => { let component: SomethingWentWrongComponent; let fixture: ComponentFixture; let locationStub: Location; let windowServiceStub: WindowService; let activatedRouteStub: ActivatedRoute; beforeEach(async () => { locationStub = { href: '/forløbsplan', pathname: '/', } as any; windowServiceStub = { nativeWindow: () => ({ location: locationStub } as Window), } as any; activatedRouteStub = { queryParams: of({errorMessage: 'This is an error message', errorId: '12345'}) } as any; await TestBed.configureTestingModule({ declarations: [ SomethingWentWrongComponent ], providers: [ {provide: WindowService, useValue: windowServiceStub}, {provide: ActivatedRoute, useValue: activatedRouteStub}, ], }) .compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(SomethingWentWrongComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); it('should reload window and go to pathname when onReloadButtonClick is called', () => { expect(windowServiceStub.nativeWindow().location.href).not.toBe(windowServiceStub.nativeWindow().location.pathname); component.onReloadButtonClick(); expect(windowServiceStub.nativeWindow().location.href).toBe(windowServiceStub.nativeWindow().location.pathname); }); });