Skip to content

Commit 4f7880e

Browse files
authored
Merge pull request #47 from petrzjunior/return-this
2 parents 7ffe97f + 21322d0 commit 4f7880e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,12 @@ it('should spy on Observable errors', () => {
341341
const fakeObservable = throwError('OOPS');
342342

343343
const observerSpy = new ObserverSpy({expectErrors: true}); // <-- IMPORTANT
344+
// OR
345+
const observerSpy = new ObserverSpy().expectErrors(); // <-- ALTERNATIVE WAY TO SET IT
344346

345-
// BTW, this could also be set like this:
347+
// Or even...
346348
observerSpy.expectErrors(); // <-- ALTERNATIVE WAY TO SET IT
347-
349+
348350
fakeObservable.subscribe(observerSpy);
349351

350352
expect(observerSpy.receivedError()).toBe(true);

src/observer-spy.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ describe('ObserverSpy', () => {
147147
expect(observerSpy.receivedError()).toBe(true);
148148
});
149149

150+
it('should know whether it got an "error" notification if "expectErrors" was called', () => {
151+
const observerSpy: ObserverSpy<string> = new ObserverSpy<string>().expectErrors();
152+
const { throwingObservable } = getThrowingObservable();
153+
154+
throwingObservable.subscribe(observerSpy).unsubscribe();
155+
156+
expect(observerSpy.receivedError()).toBe(true);
157+
});
158+
150159
it('should return the error object it received if "expectErrors" is configured', () => {
151160
const observerSpy: ObserverSpy<string> = new ObserverSpy({ expectErrors: true });
152161
const { throwingObservable } = getThrowingObservable();

src/observer-spy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ export class ObserverSpy<T> implements Observer<T> {
8282
});
8383
}
8484

85-
expectErrors() {
85+
expectErrors(): this {
8686
this.state.errorIsExpected = true;
87+
return this;
8788
}
8889

8990
getValuesLength(): number {

0 commit comments

Comments
 (0)