import { Location } from '@angular/common'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatMenuModule } from '@angular/material/menu'; import { MqttRequestService } from './Service/Mqtt/mqtt-request.service'; import { AppComponent } from './app.component'; describe('AppComponent', () => { let component: AppComponent; let fixture: ComponentFixture; let mqttRequestServiceSpy: jasmine.SpyObj; let locationStub: Partial; beforeEach(async () => { const mqttRequestServiceMock = jasmine.createSpyObj('MqttRequestService', ['someMethod']); locationStub = { path: () => '/home' }; await TestBed.configureTestingModule({ imports: [MatMenuModule], declarations: [AppComponent], providers: [ { provide: MqttRequestService, useValue: mqttRequestServiceMock }, { provide: Location, useValue: locationStub } ] }).compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(AppComponent); component = fixture.componentInstance; mqttRequestServiceSpy = TestBed.inject(MqttRequestService) as jasmine.SpyObj; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); it('should set header to "Home" if the route is empty', () => { expect(component.header).toBe('Home'); }); it('should set header to the capitalized route value', () => { locationStub.path = () => '/about'; const componentNew = new AppComponent(mqttRequestServiceSpy, locationStub as Location); expect(componentNew.header).toBe('About'); }); it('should update header when onMenuSelect is called', () => { component.onMenuSelect('Map'); expect(component.header).toBe('Map'); }); });