Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/angular2-pubsub.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('PubSubService', (): void => {

describe('$sub', (): void => {
it('should throw an error when event is falsy', (): void => {
expect(pubService.$sub.bind(undefined)).toThrow();
expect(() => pubService.$sub(undefined)).toThrow();
});

it('should return an observable when there is no callback', (): void => {
Expand All @@ -30,11 +30,11 @@ describe('PubSubService', (): void => {

describe('$pub', (): void => {
it('should throw an error when event is falsy', (): void => {
expect(pubService.$pub.bind(undefined)).toThrow();
expect(() => pubService.$pub(undefined)).toThrow();
});

it('should throw an error when event is not registered', (): void => {
expect(pubService.$pub.bind('not-registered')).toThrow();
it('should do nothing when an event is not registered', (): void => {
expect(() => pubService.$pub('not-registered')).not.toThrow();
});

it('should publish with parameters if the event is registered', (): void => {
Expand Down
6 changes: 3 additions & 3 deletions src/angular2-pubsub.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';

Expand All @@ -21,7 +21,7 @@ export class PubSubService implements IPubSubService {
}

if (this.events[event] === undefined) {
this.events[event] = new BehaviorSubject<any>(0);
this.events[event] = new ReplaySubject<any>();
}

if (typeof callback !== 'function') {
Expand All @@ -35,7 +35,7 @@ export class PubSubService implements IPubSubService {
if (!event) {
throw new Error(`[${ServiceName}] => Publish method must get event name.`);
} else if (!this.events[event]) {
throw new Error(`[${ServiceName}] => No recorded events found for ${event}.`);
return;
}

this.events[event].next(eventObject);
Expand Down