Skip to content

Commit

Permalink
fix: added logging for not-found component (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal authored Jul 12, 2022
1 parent e5f6bc0 commit 6781b33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import { ComponentFixture, TestBed } from "@angular/core/testing";
import { NotFoundComponent } from "./not-found.component";
import { RouterTestingModule } from "@angular/router/testing";
import { ViewModule } from "../../view.module";
import { LOCATION_TOKEN } from "../../../../utils/di-tokens";
import { LoggingService } from "../../../logging/logging.service";

describe("NotFoundComponent", () => {
let component: NotFoundComponent;
let fixture: ComponentFixture<NotFoundComponent>;
let mockLogging: jasmine.SpyObj<LoggingService>;

beforeEach(async () => {
mockLogging = jasmine.createSpyObj(LoggingService.name, ["warn"]);
await TestBed.configureTestingModule({
imports: [ViewModule, RouterTestingModule],
providers: [
{ provide: LOCATION_TOKEN, useValue: { pathname: "/some/path" } },
{ provide: LoggingService, useValue: mockLogging },
],
}).compileComponents();
});

Expand All @@ -23,4 +31,10 @@ describe("NotFoundComponent", () => {
it("should create", () => {
expect(component).toBeTruthy();
});

it("should call logging service with current route", () => {
expect(mockLogging.warn).toHaveBeenCalledWith(
"Could not find component for route: /some/path"
);
});
});
17 changes: 15 additions & 2 deletions src/app/core/view/dynamic-routing/not-found/not-found.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { Component } from "@angular/core";
import { Component, Inject, OnInit } from "@angular/core";
import { LoggingService } from "../../../logging/logging.service";
import { LOCATION_TOKEN } from "../../../../utils/di-tokens";

@Component({
selector: "app-not-found",
templateUrl: "./not-found.component.html",
styleUrls: ["./not-found.component.scss"],
})
export class NotFoundComponent {}
export class NotFoundComponent implements OnInit {
constructor(
private loggingService: LoggingService,
@Inject(LOCATION_TOKEN) private location: Location
) {}

ngOnInit() {
this.loggingService.warn(
"Could not find component for route: " + this.location.pathname
);
}
}

0 comments on commit 6781b33

Please sign in to comment.