From: Kai Moritz Date: Tue, 16 Sep 2025 20:28:18 +0000 (+0200) Subject: fix: Fixed unit-tests X-Git-Tag: jest--2025-10-04--09-27~29 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=9953ab3639c978310d7f0bb42a3082efb251bf32;p=demos%2Fkafka%2Fchat fix: Fixed unit-tests --- diff --git a/src/app/app.component.html b/src/app/app.component.html index 2a45bdd9..92217a71 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,4 +1,4 @@ -
+ -
+
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index c1f36a57..97e5fe9e 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -20,16 +20,17 @@ describe('AppComponent', () => { expect(app).toBeTruthy(); }); - it(`should have as title 'chatroom-frontend'`, () => { + it('should render the header', () => { const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app.title).toEqual('chatroom-frontend'); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('div.header')).toBeDefined(); }); - it('should render title', () => { + it('should render the content', () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('.content span')?.textContent).toContain('chatroom-frontend app is running!'); + expect(compiled.querySelector('div.content')).toBeDefined(); }); }); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 283aedcf..9a05a567 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -6,5 +6,5 @@ import { Component } from '@angular/core'; styleUrls: ['./app.component.less'] }) export class AppComponent { - title = 'Chatroom'; + title = 'chatroom-frontend'; } diff --git a/src/app/chatroom/chatroom.component.spec.ts b/src/app/chatroom/chatroom.component.spec.ts index 6ebaacfe..ded23f2e 100644 --- a/src/app/chatroom/chatroom.component.spec.ts +++ b/src/app/chatroom/chatroom.component.spec.ts @@ -1,5 +1,6 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; - +import { RouterTestingModule } from '@angular/router/testing'; import { ChatroomComponent } from './chatroom.component'; describe('ChatroomComponent', () => { @@ -8,6 +9,10 @@ describe('ChatroomComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + RouterTestingModule, + ], declarations: [ ChatroomComponent ] }) .compileComponents(); diff --git a/src/app/chatroom/chatroom.service.spec.ts b/src/app/chatroom/chatroom.service.spec.ts index af0ed87d..2117adc0 100644 --- a/src/app/chatroom/chatroom.service.spec.ts +++ b/src/app/chatroom/chatroom.service.spec.ts @@ -1,12 +1,18 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { TestBed } from '@angular/core/testing'; - +import { RouterTestingModule } from '@angular/router/testing'; import { ChatroomService } from './chatroom.service'; describe('ChatroomService', () => { let service: ChatroomService; beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + RouterTestingModule, + ], + }); service = TestBed.inject(ChatroomService); }); diff --git a/src/app/chatrooms/chatrooms.component.spec.ts b/src/app/chatrooms/chatrooms.component.spec.ts index b9a1a6f8..2b795cf3 100644 --- a/src/app/chatrooms/chatrooms.component.spec.ts +++ b/src/app/chatrooms/chatrooms.component.spec.ts @@ -1,5 +1,5 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; - import { ChatroomsComponent } from './chatrooms.component'; describe('ChatroomsComponent', () => { @@ -8,6 +8,7 @@ describe('ChatroomsComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ + imports: [ HttpClientTestingModule ], declarations: [ ChatroomsComponent ] }) .compileComponents(); diff --git a/src/app/user/user.component.spec.ts b/src/app/user/user.component.spec.ts index aaf6c19a..5d815c05 100644 --- a/src/app/user/user.component.spec.ts +++ b/src/app/user/user.component.spec.ts @@ -1,5 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; - +import { ReactiveFormsModule } from '@angular/forms'; import { UserComponent } from './user.component'; describe('UserComponent', () => { @@ -8,6 +8,7 @@ describe('UserComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ + imports: [ ReactiveFormsModule ], declarations: [ UserComponent ] }) .compileComponents(); @@ -17,7 +18,7 @@ describe('UserComponent', () => { fixture.detectChanges(); }); - it('should create', () => { + it('should be create', () => { expect(component).toBeTruthy(); }); });