my-chat-room/apps/chat-room/src/app/app.component.spec.ts

33 lines
1.0 KiB
TypeScript

import { TestBed, waitForAsync } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { MockService } from 'ng-mocks';
import { AppComponent } from './app.component';
import { MessagesService } from './messages.service';
import { of } from 'rxjs';
describe('AppComponent', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
imports: [HttpClientModule, FormsModule],
providers: [
{ provide: MessagesService, useValue: MockService(MessagesService) },
],
}).compileComponents();
})
);
beforeEach(() => {
const messageService = TestBed.inject(MessagesService);
jest.spyOn(messageService, 'getMessages').mockReturnValue(of([]));
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
});