-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(delay): accepts absolute time delay
- delay operator accepts absolute time as well as relative time - add additional test coverages relates to #549
- Loading branch information
Showing
2 changed files
with
129 additions
and
53 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,11 +1,96 @@ | ||
/* globals describe, it, expect, expectObservable, hot, rxTestScheduler */ | ||
/* globals describe, it, expect, expectObservable, expectSubscriptions, hot, rxTestScheduler */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('Observable.prototype.delay()', function () { | ||
it('should delay by specified timeframe', function () { | ||
var source = hot('--a--|'); | ||
var expected = '-----a--|'; | ||
var e1 = hot('--a--b--|'); | ||
var expected = '-----a--b--|'; | ||
var subs = '^ !'; | ||
|
||
expectObservable(source.delay(30, rxTestScheduler)).toBe(expected); | ||
expectObservable(e1.delay(30, rxTestScheduler)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(subs); | ||
}); | ||
|
||
it('should delay by absolute time period', function () { | ||
var e1 = hot('--a--b--|'); | ||
var expected = '-----a--b--|'; | ||
var subs = '^ !'; | ||
var absoluteDelay = new Date(rxTestScheduler.now() + 30); | ||
|
||
expectObservable(e1.delay(absoluteDelay, rxTestScheduler)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(subs); | ||
}); | ||
|
||
it('should delay by absolute time period after subscription', function () { | ||
var e1 = hot('---^--a--b--|'); | ||
var expected = '------a--b--|'; | ||
var subs = '^ !'; | ||
var absoluteDelay = new Date(rxTestScheduler.now() + 30); | ||
|
||
expectObservable(e1.delay(absoluteDelay, rxTestScheduler)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(subs); | ||
}); | ||
|
||
it('should raise error when source raises error', function () { | ||
var e1 = hot('---a---b---#'); | ||
var expected = '------a---b#'; | ||
var subs = '^ !'; | ||
|
||
expectObservable(e1.delay(30, rxTestScheduler)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(subs); | ||
}); | ||
|
||
it('should raise error when source raises error', function () { | ||
var e1 = hot('--a--b--#'); | ||
var expected = '-----a--#'; | ||
var subs = '^ !'; | ||
var absoluteDelay = new Date(rxTestScheduler.now() + 30); | ||
|
||
expectObservable(e1.delay(absoluteDelay, rxTestScheduler)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(subs); | ||
}); | ||
|
||
it('should raise error when source raises error after subscription', function () { | ||
var e1 = hot('---^---a---b---#'); | ||
var expected = '-------a---b#'; | ||
var e1Sub = '^ !'; | ||
var absoluteDelay = new Date(rxTestScheduler.now() + 30); | ||
|
||
expectObservable(e1.delay(absoluteDelay, rxTestScheduler)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1Sub); | ||
}); | ||
|
||
it('should delay when source does not emits', function () { | ||
var e1 = hot('----|'); | ||
var expected = '-------|'; | ||
var subs = '^ !'; | ||
|
||
expectObservable(e1.delay(30, rxTestScheduler)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(subs); | ||
}); | ||
|
||
it('should delay when source is empty', function () { | ||
var e1 = Observable.empty(); | ||
var expected = '---|'; | ||
|
||
expectObservable(e1.delay(30, rxTestScheduler)).toBe(expected); | ||
}); | ||
|
||
it('should not complete when source does not completes', function () { | ||
var e1 = hot('---a---b-'); | ||
var expected = '------a---b-'; | ||
var unsub = '----------------!'; | ||
var subs = '^ !'; | ||
|
||
expectObservable(e1.delay(30, rxTestScheduler), unsub).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(subs); | ||
}); | ||
|
||
it('should not complete when source never completes', function () { | ||
var e1 = Observable.never(); | ||
var expected = '-'; | ||
|
||
expectObservable(e1.delay(30, rxTestScheduler)).toBe(expected); | ||
}); | ||
}); |
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