|
1 | 1 | import { expect } from 'chai';
|
2 |
| -import { SubscriptionLog } from 'rxjs/testing/SubscriptionLog'; |
3 | 2 | import { marbleAssert } from '../../src/assert/marbleAssert';
|
4 | 3 | import { parseObservableMarble as p } from '../../src/marbles/parseObservableMarble';
|
| 4 | +import { subscribe } from '../../src/message/TestMessage'; |
5 | 5 |
|
6 | 6 | describe('marbleAssert', () => {
|
7 | 7 | it('should throw if source is neither array nor SubscriptionLog', () => {
|
8 | 8 | expect(() => marbleAssert(1 as any)).to.throw();
|
9 | 9 | });
|
10 | 10 |
|
11 | 11 | describe('TestMessage', () => {
|
12 |
| - it(`should throw if expected value isn't array`, () => { |
13 |
| - expect(() => marbleAssert([]).to.equal(new SubscriptionLog(0) as any)).to.throw(); |
| 12 | + it('shoud pass empty', () => { |
| 13 | + marbleAssert(p('------')).to.equal(p('------')); |
| 14 | + marbleAssert([]).to.equal(p('------')); |
| 15 | + marbleAssert([]).to.equal([]); |
14 | 16 | });
|
15 | 17 |
|
16 | 18 | it('should pass observables', () => {
|
17 | 19 | const s = p('--a--b--');
|
18 | 20 | const e = p('--a--b--');
|
19 | 21 |
|
20 |
| - marbleAssert(s).to.equal(e); |
| 22 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
21 | 23 | });
|
22 | 24 |
|
23 | 25 | it('should pass observable with noop', () => {
|
24 | 26 | const s = p('--a- -b--');
|
25 | 27 | const e = p('--a- -b--');
|
26 | 28 |
|
27 |
| - marbleAssert(s).to.equal(e); |
| 29 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
28 | 30 | });
|
29 | 31 |
|
30 | 32 | it('should pass observable with groups', () => {
|
31 | 33 | const s = p('--(ab)-c-');
|
32 | 34 | const e = p('--(ab)-c--');
|
33 | 35 |
|
34 |
| - marbleAssert(s).to.equal(e); |
| 36 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
35 | 37 | });
|
36 | 38 |
|
37 | 39 | it('should pass observable with expand', () => {
|
38 | 40 | const s = p('--a-...3...-b--');
|
39 | 41 | const e = p('--a-----b--');
|
40 | 42 |
|
41 |
| - marbleAssert(s).to.equal(e); |
| 43 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
42 | 44 | });
|
43 | 45 |
|
44 | 46 | it('should pass observable with complete', () => {
|
45 | 47 | const s = p('a--b--|');
|
46 | 48 | const e = p('a--b--|');
|
47 | 49 |
|
48 |
| - marbleAssert(s).to.equal(e); |
| 50 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
49 | 51 | });
|
50 | 52 |
|
51 | 53 | it('should pass observable with synchronous group', () => {
|
52 | 54 | const s = p('(a|)');
|
53 | 55 | const e = p('(a|)');
|
54 | 56 |
|
55 |
| - marbleAssert(s).to.equal(e); |
| 57 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
56 | 58 | });
|
57 | 59 |
|
58 | 60 | it('should pass observable with error', () => {
|
59 | 61 | const s = p('--a--b--#');
|
60 | 62 | const e = p('--a--b--#');
|
61 | 63 |
|
62 |
| - marbleAssert(s).to.equal(e); |
| 64 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
63 | 65 | });
|
64 | 66 |
|
65 | 67 | it('should pass observable with custom value', () => {
|
66 | 68 | const s = p('--a--b--', { a: 1 });
|
67 | 69 | const e = p('--a--b--', { a: 1 });
|
68 | 70 |
|
69 |
| - marbleAssert(s).to.equal(e); |
| 71 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
70 | 72 | });
|
71 | 73 |
|
72 | 74 | it('should pass observable with custom error', () => {
|
73 | 75 | const s = p('--a--b--#', null, 1);
|
74 | 76 | const e = p('--a--b--#', null, 1);
|
75 | 77 |
|
76 |
| - marbleAssert(s).to.equal(e); |
| 78 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
77 | 79 | });
|
78 | 80 |
|
79 | 81 | it('should pass hot observable with subscription, without emit before sub', () => {
|
80 | 82 | const s = p('^--a--b--');
|
81 | 83 | const e = p('---a--b--');
|
82 | 84 |
|
83 |
| - marbleAssert(s).to.equal(e); |
| 85 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
84 | 86 | });
|
85 | 87 |
|
86 | 88 | it('should pass hot observable with subscription, emit before sub', () => {
|
87 | 89 | const s = p('-x--^--a--b--');
|
88 | 90 | const e = p('-x--^--a--b--');
|
89 | 91 |
|
90 |
| - marbleAssert(s).to.equal(e); |
| 92 | + expect(() => marbleAssert(s).to.equal(e)).to.not.throw(); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should assert empty source', () => { |
| 96 | + expect(() => marbleAssert([]).to.equal(p('----s'))).to.throw(); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should assert non-array expected', () => { |
| 100 | + expect(() => marbleAssert([]).to.equal('1' as any)).to.throw(); |
91 | 101 | });
|
92 | 102 |
|
93 | 103 | it('should assert observables frame', () => {
|
@@ -176,65 +186,96 @@ describe('marbleAssert', () => {
|
176 | 186 | });
|
177 | 187 |
|
178 | 188 | describe('SubscriptionLog', () => {
|
179 |
| - it(`should throw if expected value isn't subscription log`, () => { |
180 |
| - expect(() => marbleAssert(new SubscriptionLog(0, 0)).to.equal([] as any)).to.throw(); |
181 |
| - }); |
182 |
| - |
183 | 189 | it('should pass if subscription matches', () => {
|
184 |
| - const source = new SubscriptionLog(10); |
| 190 | + const source = [subscribe(10)]; |
185 | 191 |
|
186 | 192 | expect(() => marbleAssert(source).to.equal(source)).to.not.throw();
|
187 | 193 | });
|
188 | 194 |
|
189 | 195 | it('should pass if subscription with unsubscription matches', () => {
|
190 |
| - const source = new SubscriptionLog(10, 45); |
| 196 | + const source = [subscribe(10, 45)]; |
191 | 197 |
|
192 | 198 | expect(() => marbleAssert(source).to.equal(source)).to.not.throw();
|
193 | 199 | });
|
194 | 200 |
|
195 | 201 | it('should pass if unsubscription matches', () => {
|
196 |
| - const source = new SubscriptionLog(Number.POSITIVE_INFINITY, 20); |
| 202 | + const source = [subscribe(Number.POSITIVE_INFINITY, 20)]; |
197 | 203 |
|
198 | 204 | expect(() => marbleAssert(source).to.equal(source)).to.not.throw();
|
199 | 205 | });
|
200 | 206 |
|
201 | 207 | it('should pass if subscription is empty', () => {
|
202 |
| - const source = new SubscriptionLog(Number.POSITIVE_INFINITY); |
| 208 | + const source = [subscribe(Number.POSITIVE_INFINITY)]; |
203 | 209 |
|
204 | 210 | expect(() => marbleAssert(source).to.equal(source)).to.not.throw();
|
205 | 211 | });
|
206 | 212 |
|
| 213 | + it('should pass multiple subscriptions', () => { |
| 214 | + const source = [subscribe(10, 45), subscribe(20, 35)]; |
| 215 | + |
| 216 | + expect(() => marbleAssert(source).to.equal(source)).to.not.throw(); |
| 217 | + }); |
| 218 | + |
| 219 | + it('should assert empty source', () => { |
| 220 | + expect(() => marbleAssert([]).to.equal([subscribe(10, 24)] as any)).to.throw(); |
| 221 | + }); |
| 222 | + |
| 223 | + it('should assert non-array expected', () => { |
| 224 | + expect(() => marbleAssert([]).to.equal('1' as any)).to.throw(); |
| 225 | + }); |
| 226 | + |
207 | 227 | it('should assert if subscription unmatches', () => {
|
208 |
| - const source = new SubscriptionLog(10); |
209 |
| - const expected = new SubscriptionLog(20); |
| 228 | + const source = [subscribe(10)]; |
| 229 | + const expected = [subscribe(20)]; |
210 | 230 |
|
211 | 231 | expect(() => marbleAssert(source).to.equal(expected)).to.throw();
|
212 | 232 | });
|
213 | 233 |
|
214 | 234 | it('should assert if subscription with unsubscription unmatches', () => {
|
215 |
| - const source = new SubscriptionLog(10, 45); |
216 |
| - const expected = new SubscriptionLog(12, 46); |
| 235 | + const source = [subscribe(10, 45)]; |
| 236 | + const expected = [subscribe(12, 46)]; |
217 | 237 |
|
218 | 238 | expect(() => marbleAssert(source).to.equal(expected)).to.throw();
|
219 | 239 | });
|
220 | 240 |
|
221 | 241 | it('should assert if subscription unmatches with unsubscription', () => {
|
222 |
| - const source = new SubscriptionLog(10, 45); |
223 |
| - const expected = new SubscriptionLog(12, 45); |
| 242 | + const source = [subscribe(10, 45)]; |
| 243 | + const expected = [subscribe(12, 45)]; |
224 | 244 |
|
225 | 245 | expect(() => marbleAssert(source).to.equal(expected)).to.throw();
|
226 | 246 | });
|
227 | 247 |
|
228 | 248 | it('should assert if unsubscription with subscription unmatches', () => {
|
229 |
| - const source = new SubscriptionLog(10, 45); |
230 |
| - const expected = new SubscriptionLog(10, 46); |
| 249 | + const source = [subscribe(10, 45)]; |
| 250 | + const expected = [subscribe(10, 46)]; |
231 | 251 |
|
232 | 252 | expect(() => marbleAssert(source).to.equal(expected)).to.throw();
|
233 | 253 | });
|
234 | 254 |
|
235 | 255 | it('should assert if unsubscription unmatches', () => {
|
236 |
| - const source = new SubscriptionLog(Number.POSITIVE_INFINITY, 20); |
237 |
| - const expected = new SubscriptionLog(Number.POSITIVE_INFINITY, 30); |
| 256 | + const source = [subscribe(Number.POSITIVE_INFINITY, 20)]; |
| 257 | + const expected = [subscribe(Number.POSITIVE_INFINITY, 30)]; |
| 258 | + |
| 259 | + expect(() => marbleAssert(source).to.equal(expected)).to.throw(); |
| 260 | + }); |
| 261 | + |
| 262 | + it('should assert same length multiple subscription', () => { |
| 263 | + const source = [subscribe(10, 45), subscribe(5, 35), subscribe(10, 46)]; |
| 264 | + const expected = [subscribe(10, 46), subscribe(5, 35), subscribe(10, 45)]; |
| 265 | + |
| 266 | + expect(() => marbleAssert(source).to.equal(expected)).to.throw(); |
| 267 | + }); |
| 268 | + |
| 269 | + it('should assert larger source multiple subscription', () => { |
| 270 | + const source = [subscribe(10, 45), subscribe(5, 35), subscribe(10, 46), subscribe(6, 35)]; |
| 271 | + const expected = [subscribe(10, 46), subscribe(5, 35), subscribe(10, 45)]; |
| 272 | + |
| 273 | + expect(() => marbleAssert(source).to.equal(expected)).to.throw(); |
| 274 | + }); |
| 275 | + |
| 276 | + it('should assert larger expected multiple subscription', () => { |
| 277 | + const source = [subscribe(10, 45), subscribe(5, 35), subscribe(10, 46)]; |
| 278 | + const expected = [subscribe(10, 46), subscribe(5, 35), subscribe(10, 45), subscribe(6, 35)]; |
238 | 279 |
|
239 | 280 | expect(() => marbleAssert(source).to.equal(expected)).to.throw();
|
240 | 281 | });
|
|
0 commit comments