Skip to content

Commit

Permalink
Add basic regression test for issues #7608 and #9690.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed May 9, 2022
1 parent 6c53754 commit 0779485
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/utilities/observables/__tests__/Concast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,50 @@ describe("Concast Observable (similar to Behavior Subject in RxJS)", () => {
},
});
});

itAsync("behaves appropriately if unsubscribed before first result", (resolve, reject) => {
const concast = new Concast([
new Promise(resolve => setTimeout(resolve, 100)).then(
() => Observable.of(1, 2, 3),
),
]);

const cleanupCounts = {
first: 0,
second: 0,
};

concast.cleanup(() => {
++cleanupCounts.first;
});

const unsubscribe = concast.subscribe({
next() {
reject("should not have called observer.next");
},
error() {
reject("should not have called observer.error");
},
complete() {
reject("should not have called observer.complete");
},
});

concast.cleanup(() => {
++cleanupCounts.second;
});

// Immediately unsubscribe the observer we just added, triggering
// completion.
unsubscribe.unsubscribe();

return concast.promise.then(finalResult => {
expect(finalResult).toBeUndefined();
expect(cleanupCounts).toEqual({
first: 1,
second: 1,
});
resolve();
}).catch(reject);
});
});

0 comments on commit 0779485

Please sign in to comment.