|
6 | 6 | takeWhile,
|
7 | 7 | switchMapTo,
|
8 | 8 | delay,
|
| 9 | + startWith, |
9 | 10 | } from "rxjs/operators"
|
10 | 11 | import { TestScheduler } from "rxjs/testing"
|
11 | 12 | import { selfDependent } from "."
|
@@ -53,4 +54,64 @@ describe("selfDependent", () => {
|
53 | 54 | expectSubscriptions((source as any).subscriptions).toBe(sourceSub)
|
54 | 55 | })
|
55 | 56 | })
|
| 57 | + |
| 58 | + it("works after unsubscription and re-subscription", () => { |
| 59 | + scheduler().run(({ expectObservable, cold }) => { |
| 60 | + const source = cold("abcde") |
| 61 | + const sourceSub1 = " ^--!" |
| 62 | + const expected1 = " abc" |
| 63 | + const sourceSub2 = " -----^---!" |
| 64 | + const expected2 = " -----abcd" |
| 65 | + |
| 66 | + const [lastValue$, connect] = selfDependent<string>() |
| 67 | + const result$ = source.pipe( |
| 68 | + withLatestFrom(lastValue$.pipe(startWith(""))), |
| 69 | + map(([v]) => v), |
| 70 | + connect(), |
| 71 | + ) |
| 72 | + |
| 73 | + expectObservable(result$, sourceSub1).toBe(expected1) |
| 74 | + expectObservable(result$, sourceSub2).toBe(expected2) |
| 75 | + }) |
| 76 | + }) |
| 77 | + |
| 78 | + it("works after complete and re-subscription", () => { |
| 79 | + scheduler().run(({ expectObservable, cold }) => { |
| 80 | + const source = cold("abc|") |
| 81 | + const sourceSub1 = " ^---!" |
| 82 | + const expected1 = " abc|" |
| 83 | + const sourceSub2 = " -----^---!" |
| 84 | + const expected2 = " -----abc|" |
| 85 | + |
| 86 | + const [lastValue$, connect] = selfDependent<string>() |
| 87 | + const result$ = source.pipe( |
| 88 | + withLatestFrom(lastValue$.pipe(startWith(""))), |
| 89 | + map(([v]) => v), |
| 90 | + connect(), |
| 91 | + ) |
| 92 | + |
| 93 | + expectObservable(result$, sourceSub1).toBe(expected1) |
| 94 | + expectObservable(result$, sourceSub2).toBe(expected2) |
| 95 | + }) |
| 96 | + }) |
| 97 | + |
| 98 | + it("works after error and re-subscription", () => { |
| 99 | + scheduler().run(({ expectObservable, cold }) => { |
| 100 | + const source = cold("abc#") |
| 101 | + const sourceSub1 = " ^---!" |
| 102 | + const expected1 = " abc#" |
| 103 | + const sourceSub2 = " -----^---!" |
| 104 | + const expected2 = " -----abc#" |
| 105 | + |
| 106 | + const [lastValue$, connect] = selfDependent<string>() |
| 107 | + const result$ = source.pipe( |
| 108 | + withLatestFrom(lastValue$.pipe(startWith(""))), |
| 109 | + map(([v]) => v), |
| 110 | + connect(), |
| 111 | + ) |
| 112 | + |
| 113 | + expectObservable(result$, sourceSub1).toBe(expected1) |
| 114 | + expectObservable(result$, sourceSub2).toBe(expected2) |
| 115 | + }) |
| 116 | + }) |
56 | 117 | })
|
0 commit comments