Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(of): convert of specs to run mode (#6921)
* chore(of): convert of specs to run mode * chore(of): remove scheduler argument from specs
- Loading branch information
Showing
1 changed file
with
48 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,80 @@ | ||
/** @prettier */ | ||
import { expect } from 'chai'; | ||
import { of } from 'rxjs'; | ||
import { expectObservable } from '../helpers/marble-testing'; | ||
import { TestScheduler } from 'rxjs/testing'; | ||
import { concatMap, delay, concatAll } from 'rxjs/operators'; | ||
|
||
declare const rxTestScheduler: TestScheduler; | ||
import { observableMatcher } from '../helpers/observableMatcher'; | ||
|
||
/** @test {of} */ | ||
describe('of', () => { | ||
let rxTestScheduler: TestScheduler; | ||
|
||
beforeEach(() => { | ||
rxTestScheduler = new TestScheduler(observableMatcher); | ||
}); | ||
|
||
it('should create a cold observable that emits 1, 2, 3', () => { | ||
const e1 = of(1, 2, 3).pipe( | ||
// for the purpose of making a nice diagram, spread out the synchronous emissions | ||
concatMap((x, i) => of(x).pipe(delay(i === 0 ? 0 : 20, rxTestScheduler))) | ||
); | ||
const expected = 'x-y-(z|)'; | ||
expectObservable(e1).toBe(expected, {x: 1, y: 2, z: 3}); | ||
rxTestScheduler.run(({ expectObservable, time }) => { | ||
const delayValue = time('--|'); | ||
|
||
const e1 = of(1, 2, 3).pipe( | ||
// for the purpose of making a nice diagram, spread out the synchronous emissions | ||
concatMap((x, i) => of(x).pipe(delay(i === 0 ? 0 : delayValue))) | ||
); | ||
const expected = 'x-y-(z|)'; | ||
expectObservable(e1).toBe(expected, { x: 1, y: 2, z: 3 }); | ||
}); | ||
}); | ||
|
||
it('should create an observable from the provided values', (done) => { | ||
const x = { foo: 'bar' }; | ||
const expected = [1, 'a', x]; | ||
let i = 0; | ||
|
||
of(1, 'a', x) | ||
.subscribe({ next: (y: any) => { | ||
of(1, 'a', x).subscribe({ | ||
next: (y: any) => { | ||
expect(y).to.equal(expected[i++]); | ||
}, error: (x) => { | ||
}, | ||
error: (x) => { | ||
done(new Error('should not be called')); | ||
}, complete: () => { | ||
}, | ||
complete: () => { | ||
done(); | ||
} }); | ||
}, | ||
}); | ||
}); | ||
|
||
it('should emit one value', (done) => { | ||
let calls = 0; | ||
|
||
of(42).subscribe({ next: (x: number) => { | ||
expect(++calls).to.equal(1); | ||
expect(x).to.equal(42); | ||
}, error: (err: any) => { | ||
done(new Error('should not be called')); | ||
}, complete: () => { | ||
done(); | ||
} }); | ||
of(42).subscribe({ | ||
next: (x: number) => { | ||
expect(++calls).to.equal(1); | ||
expect(x).to.equal(42); | ||
}, | ||
error: (err: any) => { | ||
done(new Error('should not be called')); | ||
}, | ||
complete: () => { | ||
done(); | ||
}, | ||
}); | ||
}); | ||
|
||
it('should handle an Observable as the only value', () => { | ||
const source = of( | ||
of('a', 'b', 'c', rxTestScheduler), | ||
rxTestScheduler | ||
); | ||
const result = source.pipe(concatAll()); | ||
expectObservable(result).toBe('(abc|)'); | ||
rxTestScheduler.run(({ expectObservable }) => { | ||
const source = of(of('a', 'b', 'c')); | ||
const result = source.pipe(concatAll()); | ||
expectObservable(result).toBe('(abc|)'); | ||
}); | ||
}); | ||
|
||
it('should handle many Observable as the given values', () => { | ||
const source = of( | ||
of('a', 'b', 'c', rxTestScheduler), | ||
of('d', 'e', 'f', rxTestScheduler), | ||
rxTestScheduler | ||
); | ||
rxTestScheduler.run(({ expectObservable }) => { | ||
const source = of(of('a', 'b', 'c'), of('d', 'e', 'f')); | ||
|
||
const result = source.pipe(concatAll()); | ||
expectObservable(result).toBe('(abcdef|)'); | ||
const result = source.pipe(concatAll()); | ||
expectObservable(result).toBe('(abcdef|)'); | ||
}); | ||
}); | ||
}); |