Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(pairs): convert pairs specs to run mode (#6923)
- Loading branch information
Showing
1 changed file
with
36 additions
and
23 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,43 +1,56 @@ | ||
/** @prettier */ | ||
import { expect } from 'chai'; | ||
import { expectObservable } from '../helpers/marble-testing'; | ||
import { TestScheduler } from 'rxjs/testing'; | ||
import { pairs } from 'rxjs'; | ||
|
||
declare const rxTestScheduler: TestScheduler; | ||
import { observableMatcher } from '../helpers/observableMatcher'; | ||
|
||
describe('pairs', () => { | ||
let rxTestScheduler: TestScheduler; | ||
|
||
beforeEach(() => { | ||
rxTestScheduler = new TestScheduler(observableMatcher); | ||
}); | ||
|
||
it('should create an observable emits key-value pair', () => { | ||
const e1 = pairs({a: 1, b: 2}, rxTestScheduler); | ||
const expected = '(ab|)'; | ||
const values = { | ||
a: ['a', 1], | ||
b: ['b', 2] | ||
}; | ||
|
||
expectObservable(e1).toBe(expected, values); | ||
rxTestScheduler.run(({ expectObservable }) => { | ||
const e1 = pairs({ a: 1, b: 2 }); | ||
const expected = '(ab|)'; | ||
const values = { | ||
a: ['a', 1], | ||
b: ['b', 2], | ||
}; | ||
|
||
expectObservable(e1).toBe(expected, values); | ||
}); | ||
}); | ||
|
||
it('should create an observable without scheduler', (done) => { | ||
let expected = [ | ||
['a', 1], | ||
['b', 2], | ||
['c', 3] | ||
['c', 3], | ||
]; | ||
|
||
pairs({a: 1, b: 2, c: 3}).subscribe({ next: x => { | ||
expect(x).to.deep.equal(expected.shift()); | ||
}, error: x => { | ||
done(new Error('should not be called')); | ||
}, complete: () => { | ||
expect(expected).to.be.empty; | ||
done(); | ||
} }); | ||
pairs({ a: 1, b: 2, c: 3 }).subscribe({ | ||
next: (x) => { | ||
expect(x).to.deep.equal(expected.shift()); | ||
}, | ||
error: (x) => { | ||
done(new Error('should not be called')); | ||
}, | ||
complete: () => { | ||
expect(expected).to.be.empty; | ||
done(); | ||
}, | ||
}); | ||
}); | ||
|
||
it('should work with empty object', () => { | ||
const e1 = pairs({}, rxTestScheduler); | ||
const expected = '|'; | ||
rxTestScheduler.run(({ expectObservable }) => { | ||
const e1 = pairs({}); | ||
const expected = '|'; | ||
|
||
expectObservable(e1).toBe(expected); | ||
expectObservable(e1).toBe(expected); | ||
}); | ||
}); | ||
}); |