Skip to content

Commit

Permalink
test(flattenSequentially): add test checking stop() clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz committed Nov 17, 2016
1 parent fd31d49 commit 94f3bdc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/extra/flattenSequentially.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,36 @@ describe('flattenSequentially (extra)', () => {
},
});
});

it('should stop inner emissions if result stops', (done) => {
const expectedInner = [0, 1];

const stream = xs.of(1)
.map(i =>
xs.periodic(150).take(3) // 150ms, 300ms, 450ms, 600ms
.debug(x => assert.strictEqual(x, expectedInner.shift()))
)
.compose(flattenSequentially);

const expected = [0, 1];
const listener = {
next: (x: number) => {
assert.strictEqual(x, expected.shift());
},
error: (err: any) => done(err),
complete: () => done('should not call complete'),
};

stream.addListener(listener);
setTimeout(() => {
stream.removeListener(listener);
}, 390);

setTimeout(() => {
assert.strictEqual(expectedInner.length, 0);
assert.strictEqual(expected.length, 0);
done();
}, 500);
});
});
});

0 comments on commit 94f3bdc

Please sign in to comment.