-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugConfirmed bugConfirmed bug
Description
Describe the bug
When using expectObservable from the TestScheduler with subscription marbles:
const actual = createTestObservable();
const expected = createExpectedObservable();
expectObservable(actual, '^---!').toEqual(expected);When the ! marble is scheduled, only the expected observable will be unsubscribed and not the actual observable. This seems to be because the implementation shares the same subscription variable, so when expected is subscribed it overwrites the subscription from actual. Which means any custom teardown logic won't be run for actual.
Expected behavior
I'd expect the following asserts to be synonymous:
expectObservable(actual, '^---!').toBe('1234');
expectObservable(actual, '^---!').toEqual(cold('1234'));Reproduction code
import { TestScheduler } from 'rxjs/testing';
import { isEqual } from 'lodash';
import { Observable } from 'rxjs';
describe('TestScheduler', () => {
let testScheduler: TestScheduler;
let disposed = false;
beforeEach(() => {
testScheduler = new TestScheduler(isEqual);
disposed = false;
});
it('should unsubscribe toBe', () => {
testScheduler.run(({ expectObservable }) => {
expectObservable(
new Observable((_) => () => (disposed = true)),
'^!'
).toBe('');
});
expect(disposed).toBeTruthy();
});
// This fails.
it('should unsubscribe toEqual', () => {
testScheduler.run(({ cold, expectObservable }) => {
expectObservable(
new Observable((_) => () => (disposed = true)),
'^!'
).toEqual(cold(''));
});
expect(disposed).toBeTruthy();
});
});Reproduction URL
https://stackblitz.com/edit/stackblitz-starters-bs79vc?file=TestScheduler.spec.ts
Version
8.0.0-alpha.12 and 7.8.1
Environment
No response
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugConfirmed bugConfirmed bug