-
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.
feat(config): add global configuration of Promise capability
closes #115
- Loading branch information
Showing
6 changed files
with
118 additions
and
10 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
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
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,22 +1,38 @@ | ||
/* globals describe, it, expect */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var promise = require('promise'); | ||
var Promise = require('promise'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('Observable.prototype.toPromise()', function () { | ||
it('should convert an Observable to a promise of its last value', function (done) { | ||
Observable.of(1, 2, 3).toPromise(promise).then(function (x) { | ||
Observable.of(1, 2, 3).toPromise(Promise).then(function (x) { | ||
expect(x).toBe(3); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should handle errors properly', function (done) { | ||
Observable.throw('bad').toPromise(promise).then(function () { | ||
Observable.throw('bad').toPromise(Promise).then(function () { | ||
throw 'should not be called'; | ||
}, function (err) { | ||
expect(err).toBe('bad'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should allow for global config via Rx.config.Promise', function(done){ | ||
var wasCalled = false; | ||
__root__.Rx = {}; | ||
__root__.Rx.config = {}; | ||
__root__.Rx.config.Promise = function MyPromise(callback) { | ||
wasCalled = true; | ||
return new Promise(callback); | ||
}; | ||
|
||
Observable.of(42).toPromise().then(function(x) { | ||
expect(wasCalled).toBe(true); | ||
expect(x).toBe(42); | ||
done(); | ||
}); | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -241,5 +241,5 @@ export { | |
VirtualTimeScheduler, | ||
TestScheduler, | ||
EmptyError, | ||
ArgumentOutOfRangeError | ||
ArgumentOutOfRangeError, | ||
}; |
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