import { BaseRequestOptions, ConnectionBackend, Http, Response, ResponseOptions } from '@angular/http'; import { inject, TestBed } from '@angular/core/testing'; import { MockBackend } from '@angular/http/testing'; import { Observable } from 'rxjs/Observable'; import { BroadcastMessage, MessageType } from './broadcast.payload'; import { IBroadcastService } from './broadcast.interface'; import { BroadcastService } from './broadcast.service'; describe('Broadcast Service', () => { let broadcastSvc: IBroadcastService; let mockBackend: MockBackend; beforeEach(() => { TestBed.configureTestingModule({ providers: [ BroadcastService, MockBackend, BaseRequestOptions, { provide: Http, useFactory: (backend: ConnectionBackend, options: BaseRequestOptions) => new Http(backend, options), deps: [MockBackend, BaseRequestOptions] } ] }); }); it('should publish message and receive message when publish method is called', () => { let broadcastService: IBroadcastService = TestBed.get(BroadcastService); let payLoad: BroadcastMessage = >{ messageType: MessageType.Search, payLoad: 'This is my payload' }; expect(broadcastService).not.toBeNull(); broadcastService.receiveMessage().subscribe((data: BroadcastMessage) => { expect(data.messageType).toBe(MessageType.Search, 'Message Type is wrong!'); expect(data.payLoad).toBe('This is my payload', 'Value is not the same!'); }); broadcastService.publishMessage(payLoad); }); });