| 1 |
var failIfThrows = function (done) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
return function (e) { |
| 5 |
done(e || new Error()); |
| 6 |
}; |
| 7 |
}; |
| 8 |
|
| 9 |
describe('Promise.reject', function () { |
| 10 |
'use strict'; |
| 11 |
|
| 12 |
it('should not be enumerable', function () { |
| 13 |
expect(Promise).ownPropertyDescriptor('reject').to.have.property('enumerable', false); |
| 14 |
}); |
| 15 |
|
| 16 |
it('should return a rejected promise', function (done) { |
| 17 |
var value = {}; |
| 18 |
Promise.reject(value).then(failIfThrows(done), function (result) { |
| 19 |
expect(result).to.equal(value); |
| 20 |
done(); |
| 21 |
}); |
| 22 |
}); |
| 23 |
|
| 24 |
it('throws when receiver is a primitive', function () { |
| 25 |
var promise = Promise.reject(); |
| 26 |
expect(function () { Promise.reject.call(undefined, promise); }).to['throw'](); |
| 27 |
expect(function () { Promise.reject.call(null, promise); }).to['throw'](); |
| 28 |
expect(function () { Promise.reject.call('', promise); }).to['throw'](); |
| 29 |
expect(function () { Promise.reject.call(42, promise); }).to['throw'](); |
| 30 |
expect(function () { Promise.reject.call(false, promise); }).to['throw'](); |
| 31 |
expect(function () { Promise.reject.call(true, promise); }).to['throw'](); |
| 32 |
promise.then(null, function () {}); // silence unhandled rejection errors in Chrome |
| 33 |
}); |
| 34 |
}); |