resolve.js 1.1 KB

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