Best JavaScript code snippet using wpt
2.3.3.js
Source:2.3.3.js
...55 describe("`then` calls `rejectPromise` synchronously", function () {56 function xFactory() {57 return {58 then: function (resolvePromise, rejectPromise) {59 rejectPromise(r);60 }61 };62 }63 testPromiseResolution(xFactory, test);64 });65 describe("`then` calls `rejectPromise` asynchronously", function () {66 function xFactory() {67 return {68 then: function (resolvePromise, rejectPromise) {69 setTimeout(function () {70 rejectPromise(r);71 }, 0);72 }73 };74 }75 testPromiseResolution(xFactory, test);76 });77 });78}79function testCallingResolvePromiseFulfillsWith(yFactory, stringRepresentation, fulfillmentValue) {80 testCallingResolvePromise(yFactory, stringRepresentation, function (promise, done) {81 promise.then(function onPromiseFulfilled(value) {82 assert.strictEqual(value, fulfillmentValue);83 done();84 });85 });86}87function testCallingResolvePromiseRejectsWith(yFactory, stringRepresentation, rejectionReason) {88 testCallingResolvePromise(yFactory, stringRepresentation, function (promise, done) {89 promise.then(null, function onPromiseRejected(reason) {90 assert.strictEqual(reason, rejectionReason);91 done();92 });93 });94}95function testCallingRejectPromiseRejectsWith(reason, stringRepresentation) {96 testCallingRejectPromise(reason, stringRepresentation, function (promise, done) {97 promise.then(null, function onPromiseRejected(rejectionReason) {98 assert.strictEqual(rejectionReason, reason);99 done();100 });101 });102}103describe("2.3.3: Otherwise, if `x` is an object or function,", function () {104 describe("2.3.3.1: Let `then` be `x.then`", function () {105 describe("`x` is an object with null prototype", function () {106 var numberOfTimesThenWasRetrieved = null;107 beforeEach(function () {108 numberOfTimesThenWasRetrieved = 0;109 });110 function xFactory() {111 return Object.create(null, {112 then: {113 get: function () {114 ++numberOfTimesThenWasRetrieved;115 return function thenMethodForX(onFulfilled) {116 onFulfilled();117 };118 }119 }120 });121 }122 testPromiseResolution(xFactory, function (promise, done) {123 promise.then(function () {124 assert.strictEqual(numberOfTimesThenWasRetrieved, 1);125 done();126 });127 });128 });129 describe("`x` is an object with normal Object.prototype", function () {130 var numberOfTimesThenWasRetrieved = null;131 beforeEach(function () {132 numberOfTimesThenWasRetrieved = 0;133 });134 function xFactory() {135 return Object.create(Object.prototype, {136 then: {137 get: function () {138 ++numberOfTimesThenWasRetrieved;139 return function thenMethodForX(onFulfilled) {140 onFulfilled();141 };142 }143 }144 });145 }146 testPromiseResolution(xFactory, function (promise, done) {147 promise.then(function () {148 assert.strictEqual(numberOfTimesThenWasRetrieved, 1);149 done();150 });151 });152 });153 describe("`x` is a function", function () {154 var numberOfTimesThenWasRetrieved = null;155 beforeEach(function () {156 numberOfTimesThenWasRetrieved = 0;157 });158 function xFactory() {159 function x() { }160 Object.defineProperty(x, "then", {161 get: function () {162 ++numberOfTimesThenWasRetrieved;163 return function thenMethodForX(onFulfilled) {164 onFulfilled();165 };166 }167 });168 return x;169 }170 testPromiseResolution(xFactory, function (promise, done) {171 promise.then(function () {172 assert.strictEqual(numberOfTimesThenWasRetrieved, 1);173 done();174 });175 });176 });177 });178 describe("2.3.3.2: If retrieving the property `x.then` results in a thrown exception `e`, reject `promise` with " +179 "`e` as the reason.", function () {180 function testRejectionViaThrowingGetter(e, stringRepresentation) {181 function xFactory() {182 return Object.create(Object.prototype, {183 then: {184 get: function () {185 throw e;186 }187 }188 });189 }190 describe("`e` is " + stringRepresentation, function () {191 testPromiseResolution(xFactory, function (promise, done) {192 promise.then(null, function (reason) {193 assert.strictEqual(reason, e);194 done();195 });196 });197 });198 }199 Object.keys(reasons).forEach(function (stringRepresentation) {200 testRejectionViaThrowingGetter(reasons[stringRepresentation], stringRepresentation);201 });202 });203 describe("2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and " +204 "second argument `rejectPromise`", function () {205 describe("Calls with `x` as `this` and two function arguments", function () {206 function xFactory() {207 var x = {208 then: function (onFulfilled, onRejected) {209 assert.strictEqual(this, x);210 assert.strictEqual(typeof onFulfilled, "function");211 assert.strictEqual(typeof onRejected, "function");212 onFulfilled();213 }214 };215 return x;216 }217 testPromiseResolution(xFactory, function (promise, done) {218 promise.then(function () {219 done();220 });221 });222 });223 describe("Uses the original value of `then`", function () {224 var numberOfTimesThenWasRetrieved = null;225 beforeEach(function () {226 numberOfTimesThenWasRetrieved = 0;227 });228 function xFactory() {229 return Object.create(Object.prototype, {230 then: {231 get: function () {232 if (numberOfTimesThenWasRetrieved === 0) {233 return function (onFulfilled) {234 onFulfilled();235 };236 }237 return null;238 }239 }240 });241 }242 testPromiseResolution(xFactory, function (promise, done) {243 promise.then(function () {244 done();245 });246 });247 });248 describe("2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)`",249 function () {250 describe("`y` is not a thenable", function () {251 testCallingResolvePromiseFulfillsWith(function () { return undefined; }, "`undefined`", undefined);252 testCallingResolvePromiseFulfillsWith(function () { return null; }, "`null`", null);253 testCallingResolvePromiseFulfillsWith(function () { return false; }, "`false`", false);254 testCallingResolvePromiseFulfillsWith(function () { return 5; }, "`5`", 5);255 testCallingResolvePromiseFulfillsWith(function () { return sentinel; }, "an object", sentinel);256 testCallingResolvePromiseFulfillsWith(function () { return sentinelArray; }, "an array", sentinelArray);257 });258 describe("`y` is a thenable", function () {259 Object.keys(thenables.fulfilled).forEach(function (stringRepresentation) {260 function yFactory() {261 return thenables.fulfilled[stringRepresentation](sentinel);262 }263 testCallingResolvePromiseFulfillsWith(yFactory, stringRepresentation, sentinel);264 });265 Object.keys(thenables.rejected).forEach(function (stringRepresentation) {266 function yFactory() {267 return thenables.rejected[stringRepresentation](sentinel);268 }269 testCallingResolvePromiseRejectsWith(yFactory, stringRepresentation, sentinel);270 });271 });272 describe("`y` is a thenable for a thenable", function () {273 Object.keys(thenables.fulfilled).forEach(function (outerStringRepresentation) {274 var outerThenableFactory = thenables.fulfilled[outerStringRepresentation];275 Object.keys(thenables.fulfilled).forEach(function (innerStringRepresentation) {276 var innerThenableFactory = thenables.fulfilled[innerStringRepresentation];277 var stringRepresentation = outerStringRepresentation + " for " + innerStringRepresentation;278 function yFactory() {279 return outerThenableFactory(innerThenableFactory(sentinel));280 }281 testCallingResolvePromiseFulfillsWith(yFactory, stringRepresentation, sentinel);282 });283 Object.keys(thenables.rejected).forEach(function (innerStringRepresentation) {284 var innerThenableFactory = thenables.rejected[innerStringRepresentation];285 var stringRepresentation = outerStringRepresentation + " for " + innerStringRepresentation;286 function yFactory() {287 return outerThenableFactory(innerThenableFactory(sentinel));288 }289 testCallingResolvePromiseRejectsWith(yFactory, stringRepresentation, sentinel);290 });291 });292 });293 });294 describe("2.3.3.3.2: If/when `rejectPromise` is called with reason `r`, reject `promise` with `r`",295 function () {296 Object.keys(reasons).forEach(function (stringRepresentation) {297 testCallingRejectPromiseRejectsWith(reasons[stringRepresentation], stringRepresentation);298 });299 });300 describe("2.3.3.3.3: If both `resolvePromise` and `rejectPromise` are called, or multiple calls to the same " +301 "argument are made, the first call takes precedence, and any further calls are ignored.",302 function () {303 describe("calling `resolvePromise` then `rejectPromise`, both synchronously", function () {304 function xFactory() {305 return {306 then: function (resolvePromise, rejectPromise) {307 resolvePromise(sentinel);308 rejectPromise(other);309 }310 };311 }312 testPromiseResolution(xFactory, function (promise, done) {313 promise.then(function (value) {314 assert.strictEqual(value, sentinel);315 done();316 });317 });318 });319 describe("calling `resolvePromise` synchronously then `rejectPromise` asynchronously", function () {320 function xFactory() {321 return {322 then: function (resolvePromise, rejectPromise) {323 resolvePromise(sentinel);324 setTimeout(function () {325 rejectPromise(other);326 }, 0);327 }328 };329 }330 testPromiseResolution(xFactory, function (promise, done) {331 promise.then(function (value) {332 assert.strictEqual(value, sentinel);333 done();334 });335 });336 });337 describe("calling `resolvePromise` then `rejectPromise`, both asynchronously", function () {338 function xFactory() {339 return {340 then: function (resolvePromise, rejectPromise) {341 setTimeout(function () {342 resolvePromise(sentinel);343 }, 0);344 setTimeout(function () {345 rejectPromise(other);346 }, 0);347 }348 };349 }350 testPromiseResolution(xFactory, function (promise, done) {351 promise.then(function (value) {352 assert.strictEqual(value, sentinel);353 done();354 });355 });356 });357 describe("calling `resolvePromise` with an asynchronously-fulfilled promise, then calling " +358 "`rejectPromise`, both synchronously", function () {359 function xFactory() {360 var d = deferred();361 setTimeout(function () {362 d.resolve(sentinel);363 }, 50);364 return {365 then: function (resolvePromise, rejectPromise) {366 resolvePromise(d.promise);367 rejectPromise(other);368 }369 };370 }371 testPromiseResolution(xFactory, function (promise, done) {372 promise.then(function (value) {373 assert.strictEqual(value, sentinel);374 done();375 });376 });377 });378 describe("calling `resolvePromise` with an asynchronously-rejected promise, then calling " +379 "`rejectPromise`, both synchronously", function () {380 function xFactory() {381 var d = deferred();382 setTimeout(function () {383 d.reject(sentinel);384 }, 50);385 return {386 then: function (resolvePromise, rejectPromise) {387 resolvePromise(d.promise);388 rejectPromise(other);389 }390 };391 }392 testPromiseResolution(xFactory, function (promise, done) {393 promise.then(null, function (reason) {394 assert.strictEqual(reason, sentinel);395 done();396 });397 });398 });399 describe("calling `rejectPromise` then `resolvePromise`, both synchronously", function () {400 function xFactory() {401 return {402 then: function (resolvePromise, rejectPromise) {403 rejectPromise(sentinel);404 resolvePromise(other);405 }406 };407 }408 testPromiseResolution(xFactory, function (promise, done) {409 promise.then(null, function (reason) {410 assert.strictEqual(reason, sentinel);411 done();412 });413 });414 });415 describe("calling `rejectPromise` synchronously then `resolvePromise` asynchronously", function () {416 function xFactory() {417 return {418 then: function (resolvePromise, rejectPromise) {419 rejectPromise(sentinel);420 setTimeout(function () {421 resolvePromise(other);422 }, 0);423 }424 };425 }426 testPromiseResolution(xFactory, function (promise, done) {427 promise.then(null, function (reason) {428 assert.strictEqual(reason, sentinel);429 done();430 });431 });432 });433 describe("calling `rejectPromise` then `resolvePromise`, both asynchronously", function () {434 function xFactory() {435 return {436 then: function (resolvePromise, rejectPromise) {437 setTimeout(function () {438 rejectPromise(sentinel);439 }, 0);440 setTimeout(function () {441 resolvePromise(other);442 }, 0);443 }444 };445 }446 testPromiseResolution(xFactory, function (promise, done) {447 promise.then(null, function (reason) {448 assert.strictEqual(reason, sentinel);449 done();450 });451 });452 });453 describe("calling `resolvePromise` twice synchronously", function () {454 function xFactory() {455 return {456 then: function (resolvePromise) {457 resolvePromise(sentinel);458 resolvePromise(other);459 }460 };461 }462 testPromiseResolution(xFactory, function (promise, done) {463 promise.then(function (value) {464 assert.strictEqual(value, sentinel);465 done();466 });467 });468 });469 describe("calling `resolvePromise` twice, first synchronously then asynchronously", function () {470 function xFactory() {471 return {472 then: function (resolvePromise) {473 resolvePromise(sentinel);474 setTimeout(function () {475 resolvePromise(other);476 }, 0);477 }478 };479 }480 testPromiseResolution(xFactory, function (promise, done) {481 promise.then(function (value) {482 assert.strictEqual(value, sentinel);483 done();484 });485 });486 });487 describe("calling `resolvePromise` twice, both times asynchronously", function () {488 function xFactory() {489 return {490 then: function (resolvePromise) {491 setTimeout(function () {492 resolvePromise(sentinel);493 }, 0);494 setTimeout(function () {495 resolvePromise(other);496 }, 0);497 }498 };499 }500 testPromiseResolution(xFactory, function (promise, done) {501 promise.then(function (value) {502 assert.strictEqual(value, sentinel);503 done();504 });505 });506 });507 describe("calling `resolvePromise` with an asynchronously-fulfilled promise, then calling it again, both " +508 "times synchronously", function () {509 function xFactory() {510 var d = deferred();511 setTimeout(function () {512 d.resolve(sentinel);513 }, 50);514 return {515 then: function (resolvePromise) {516 resolvePromise(d.promise);517 resolvePromise(other);518 }519 };520 }521 testPromiseResolution(xFactory, function (promise, done) {522 promise.then(function (value) {523 assert.strictEqual(value, sentinel);524 done();525 });526 });527 });528 describe("calling `resolvePromise` with an asynchronously-rejected promise, then calling it again, both " +529 "times synchronously", function () {530 function xFactory() {531 var d = deferred();532 setTimeout(function () {533 d.reject(sentinel);534 }, 50);535 return {536 then: function (resolvePromise) {537 resolvePromise(d.promise);538 resolvePromise(other);539 }540 };541 }542 testPromiseResolution(xFactory, function (promise, done) {543 promise.then(null, function (reason) {544 assert.strictEqual(reason, sentinel);545 done();546 });547 });548 });549 describe("calling `rejectPromise` twice synchronously", function () {550 function xFactory() {551 return {552 then: function (resolvePromise, rejectPromise) {553 rejectPromise(sentinel);554 rejectPromise(other);555 }556 };557 }558 testPromiseResolution(xFactory, function (promise, done) {559 promise.then(null, function (reason) {560 assert.strictEqual(reason, sentinel);561 done();562 });563 });564 });565 describe("calling `rejectPromise` twice, first synchronously then asynchronously", function () {566 function xFactory() {567 return {568 then: function (resolvePromise, rejectPromise) {569 rejectPromise(sentinel);570 setTimeout(function () {571 rejectPromise(other);572 }, 0);573 }574 };575 }576 testPromiseResolution(xFactory, function (promise, done) {577 promise.then(null, function (reason) {578 assert.strictEqual(reason, sentinel);579 done();580 });581 });582 });583 describe("calling `rejectPromise` twice, both times asynchronously", function () {584 function xFactory() {585 return {586 then: function (resolvePromise, rejectPromise) {587 setTimeout(function () {588 rejectPromise(sentinel);589 }, 0);590 setTimeout(function () {591 rejectPromise(other);592 }, 0);593 }594 };595 }596 testPromiseResolution(xFactory, function (promise, done) {597 promise.then(null, function (reason) {598 assert.strictEqual(reason, sentinel);599 done();600 });601 });602 });603 describe("saving and abusing `resolvePromise` and `rejectPromise`", function () {604 var savedResolvePromise, savedRejectPromise;605 function xFactory() {606 return {607 then: function (resolvePromise, rejectPromise) {608 savedResolvePromise = resolvePromise;609 savedRejectPromise = rejectPromise;610 }611 };612 }613 beforeEach(function () {614 savedResolvePromise = null;615 savedRejectPromise = null;616 });617 testPromiseResolution(xFactory, function (promise, done) {618 var timesFulfilled = 0;619 var timesRejected = 0;620 promise.then(621 function () {622 ++timesFulfilled;623 },624 function () {625 ++timesRejected;626 }627 );628 if (savedResolvePromise && savedRejectPromise) {629 savedResolvePromise(dummy);630 savedResolvePromise(dummy);631 savedRejectPromise(dummy);632 savedRejectPromise(dummy);633 }634 setTimeout(function () {635 savedResolvePromise(dummy);636 savedResolvePromise(dummy);637 savedRejectPromise(dummy);638 savedRejectPromise(dummy);639 }, 50);640 setTimeout(function () {641 assert.strictEqual(timesFulfilled, 1);642 assert.strictEqual(timesRejected, 0);643 done();644 }, 100);645 });646 });647 });648 describe("2.3.3.3.4: If calling `then` throws an exception `e`,", function () {649 describe("2.3.3.3.4.1: If `resolvePromise` or `rejectPromise` have been called, ignore it.", function () {650 describe("`resolvePromise` was called with a non-thenable", function () {651 function xFactory() {652 return {653 then: function (resolvePromise) {654 resolvePromise(sentinel);655 throw other;656 }657 };658 }659 testPromiseResolution(xFactory, function (promise, done) {660 promise.then(function (value) {661 assert.strictEqual(value, sentinel);662 done();663 });664 });665 });666 describe("`resolvePromise` was called with an asynchronously-fulfilled promise", function () {667 function xFactory() {668 var d = deferred();669 setTimeout(function () {670 d.resolve(sentinel);671 }, 50);672 return {673 then: function (resolvePromise) {674 resolvePromise(d.promise);675 throw other;676 }677 };678 }679 testPromiseResolution(xFactory, function (promise, done) {680 promise.then(function (value) {681 assert.strictEqual(value, sentinel);682 done();683 });684 });685 });686 describe("`resolvePromise` was called with an asynchronously-rejected promise", function () {687 function xFactory() {688 var d = deferred();689 setTimeout(function () {690 d.reject(sentinel);691 }, 50);692 return {693 then: function (resolvePromise) {694 resolvePromise(d.promise);695 throw other;696 }697 };698 }699 testPromiseResolution(xFactory, function (promise, done) {700 promise.then(null, function (reason) {701 assert.strictEqual(reason, sentinel);702 done();703 });704 });705 });706 describe("`rejectPromise` was called", function () {707 function xFactory() {708 return {709 then: function (resolvePromise, rejectPromise) {710 rejectPromise(sentinel);711 throw other;712 }713 };714 }715 testPromiseResolution(xFactory, function (promise, done) {716 promise.then(null, function (reason) {717 assert.strictEqual(reason, sentinel);718 done();719 });720 });721 });722 describe("`resolvePromise` then `rejectPromise` were called", function () {723 function xFactory() {724 return {725 then: function (resolvePromise, rejectPromise) {726 resolvePromise(sentinel);727 rejectPromise(other);728 throw other;729 }730 };731 }732 testPromiseResolution(xFactory, function (promise, done) {733 promise.then(function (value) {734 assert.strictEqual(value, sentinel);735 done();736 });737 });738 });739 describe("`rejectPromise` then `resolvePromise` were called", function () {740 function xFactory() {741 return {742 then: function (resolvePromise, rejectPromise) {743 rejectPromise(sentinel);744 resolvePromise(other);745 throw other;746 }747 };748 }749 testPromiseResolution(xFactory, function (promise, done) {750 promise.then(null, function (reason) {751 assert.strictEqual(reason, sentinel);752 done();753 });754 });755 });756 });757 describe("2.3.3.3.4.2: Otherwise, reject `promise` with `e` as the reason.", function () {758 describe("straightforward case", function () {759 function xFactory() {760 return {761 then: function () {762 throw sentinel;763 }764 };765 }766 testPromiseResolution(xFactory, function (promise, done) {767 promise.then(null, function (reason) {768 assert.strictEqual(reason, sentinel);769 done();770 });771 });772 });773 describe("`resolvePromise` is called asynchronously before the `throw`", function () {774 function xFactory() {775 return {776 then: function (resolvePromise) {777 setTimeout(function () {778 resolvePromise(other);779 }, 0);780 throw sentinel;781 }782 };783 }784 testPromiseResolution(xFactory, function (promise, done) {785 promise.then(null, function (reason) {786 assert.strictEqual(reason, sentinel);787 done();788 });789 });790 });791 describe("`rejectPromise` is called asynchronously before the `throw`", function () {792 function xFactory() {793 return {794 then: function (resolvePromise, rejectPromise) {795 setTimeout(function () {796 rejectPromise(other);797 }, 0);798 throw sentinel;799 }800 };801 }802 testPromiseResolution(xFactory, function (promise, done) {803 promise.then(null, function (reason) {804 assert.strictEqual(reason, sentinel);805 done();806 });807 });808 });809 });810 });...
2.3.3.spec.ts
Source:2.3.3.spec.ts
...54 describe('`then` calls `rejectPromise` synchronously', function () {55 function xFactory() {56 return {57 then: function (_: undefined, rejectPromise: (value: any) => void) {58 rejectPromise(r);59 },60 };61 }62 testPromiseResolution(xFactory, cb);63 });64 describe('`then` calls `rejectPromise` asynchronously', function () {65 function xFactory() {66 return {67 then: function (_: undefined, rejectPromise: (value: any) => void) {68 setTimeout(function () {69 rejectPromise(r);70 }, 0);71 },72 };73 }74 testPromiseResolution(xFactory, cb);75 });76 });77}78function testCallingResolvePromiseFulfillsWith(yFactory: () => {then: (...args: any) => any}, stringRepresentation: string, fulfillmentValue: any) {79 testCallingResolvePromise(yFactory, stringRepresentation, function (promise, done) {80 promise.then(function onPromiseFulfilled(value) {81 expect(value).toStrictEqual(fulfillmentValue);82 done();83 });84 });85}86function testCallingResolvePromiseRejectsWith(yFactory: () => {then: (...args: any) => any}, stringRepresentation: string, rejectionReason: any) {87 testCallingResolvePromise(yFactory, stringRepresentation, function (promise, done) {88 promise.then(null, function onPromiseRejected(reason) {89 expect(reason).toStrictEqual(rejectionReason);90 done();91 });92 });93}94function testCallingRejectPromiseRejectsWith(reason: any, stringRepresentation: string) {95 testCallingRejectPromise(reason, stringRepresentation, function (promise, done) {96 promise.then(null, function onPromiseRejected(rejectionReason) {97 expect(reason).toStrictEqual(rejectionReason);98 done();99 });100 });101}102describe('2.3.3: Otherwise, if `x` is an object or function,', function () {103 describe('2.3.3.1: Let `then` be `x.then`', function () {104 describe('`x` is an object with null prototype', function () {105 var numberOfTimesThenWasRetrieved: number;106 beforeEach(function () {107 numberOfTimesThenWasRetrieved = 0;108 });109 function xFactory() {110 return Object.create(null, {111 then: {112 get: function () {113 ++numberOfTimesThenWasRetrieved;114 return function thenMethodForX(onFulfilled: () => void) {115 onFulfilled();116 };117 },118 },119 });120 }121 testPromiseResolution(xFactory, function (promise, done) {122 promise.then(function () {123 expect(numberOfTimesThenWasRetrieved).toBe(1);124 done();125 });126 });127 });128 describe('`x` is an object with normal Object.prototype', function () {129 var numberOfTimesThenWasRetrieved: number;130 beforeEach(function () {131 numberOfTimesThenWasRetrieved = 0;132 });133 function xFactory() {134 return Object.create(Object.prototype, {135 then: {136 get: function () {137 ++numberOfTimesThenWasRetrieved;138 return function thenMethodForX(onFulfilled: () => void) {139 onFulfilled();140 };141 },142 },143 });144 }145 testPromiseResolution(xFactory, function (promise, done) {146 promise.then(function () {147 expect(numberOfTimesThenWasRetrieved).toBe(1);148 done();149 });150 });151 });152 describe('`x` is a function', function () {153 var numberOfTimesThenWasRetrieved: number;154 beforeEach(function () {155 numberOfTimesThenWasRetrieved = 0;156 });157 function xFactory() {158 function x() {}159 Object.defineProperty(x, 'then', {160 get: function () {161 ++numberOfTimesThenWasRetrieved;162 return function thenMethodForX(onFulfilled: () => void) {163 onFulfilled();164 };165 },166 });167 return x as unknown as {then: (...args: any) => any};168 }169 testPromiseResolution(xFactory, function (promise, done) {170 promise.then(function () {171 expect(numberOfTimesThenWasRetrieved).toBe(1);172 done();173 });174 });175 });176 });177 describe(178 '2.3.3.2: If retrieving the property `x.then` results in a thrown exception `e`, reject `promise` with ' + '`e` as the reason.',179 function () {180 function testRejectionViaThrowingGetter(e: any, stringRepresentation: string) {181 function xFactory() {182 return Object.create(Object.prototype, {183 then: {184 get: function () {185 throw e;186 },187 },188 });189 }190 describe('`e` is ' + stringRepresentation, function () {191 testPromiseResolution(xFactory, function (promise, done) {192 promise.then(null, function (reason) {193 expect(reason).toStrictEqual(e);194 done();195 });196 });197 });198 }199 Object.keys(reasons).forEach(function (stringRepresentation) {200 // @ts-ignore201 testRejectionViaThrowingGetter(reasons[stringRepresentation], stringRepresentation);202 });203 }204 );205 describe(206 '2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and ' + 'second argument `rejectPromise`',207 function () {208 describe('Calls with `x` as `this` and two function arguments', function () {209 function xFactory() {210 var x = {211 then: function (onFulfilled: () => void, onRejected: () => void) {212 expect(this).toStrictEqual(x);213 expect(typeof onFulfilled).toBe('function');214 expect(typeof onRejected).toBe('function');215 onFulfilled();216 },217 };218 return x;219 }220 testPromiseResolution(xFactory, function (promise: Adapter<any>, done: jest.DoneCallback) {221 promise.then(function () {222 done();223 });224 });225 });226 describe('Uses the original value of `then`', function () {227 var numberOfTimesThenWasRetrieved: number;228 beforeEach(function () {229 numberOfTimesThenWasRetrieved = 0;230 });231 function xFactory() {232 return Object.create(Object.prototype, {233 then: {234 get: function () {235 if (numberOfTimesThenWasRetrieved === 0) {236 return function (onFulfilled: () => void) {237 onFulfilled();238 };239 }240 return null;241 },242 },243 });244 }245 testPromiseResolution(xFactory, function (promise: Adapter<any>, done: jest.DoneCallback) {246 promise.then(function () {247 done();248 });249 });250 });251 describe('2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)`', function () {252 describe('`y` is not a thenable', function () {253 testCallingResolvePromiseFulfillsWith(254 function () {255 return undefined;256 } as any,257 '`undefined`',258 undefined259 );260 testCallingResolvePromiseFulfillsWith(261 function () {262 return null;263 } as any,264 '`null`',265 null266 );267 testCallingResolvePromiseFulfillsWith(268 function () {269 return false;270 } as any,271 '`false`',272 false273 );274 testCallingResolvePromiseFulfillsWith(275 function () {276 return 5;277 } as any,278 '`5`',279 5280 );281 testCallingResolvePromiseFulfillsWith(282 function () {283 return sentinel;284 } as any,285 'an object',286 sentinel287 );288 testCallingResolvePromiseFulfillsWith(289 function () {290 return sentinelArray;291 } as any,292 'an array',293 sentinelArray294 );295 });296 describe('`y` is a thenable', function () {297 Object.keys(fulfilledThen).forEach(function (stringRepresentation) {298 function yFactory() {299 // @ts-ignore300 return fulfilledThen[stringRepresentation](sentinel);301 }302 testCallingResolvePromiseFulfillsWith(yFactory, stringRepresentation, sentinel);303 });304 Object.keys(rejectedThen).forEach(function (stringRepresentation) {305 function yFactory() {306 // @ts-ignore307 return rejectedThen[stringRepresentation](sentinel);308 }309 testCallingResolvePromiseRejectsWith(yFactory, stringRepresentation, sentinel);310 });311 });312 describe('`y` is a thenable for a thenable', function () {313 Object.keys(fulfilledThen).forEach(function (outerStringRepresentation) {314 // @ts-ignore315 const outerThenableFactory = fulfilledThen[outerStringRepresentation];316 Object.keys(fulfilledThen).forEach(function (innerStringRepresentation) {317 // @ts-ignore318 const innerThenableFactory = fulfilledThen[innerStringRepresentation];319 const stringRepresentation = outerStringRepresentation + ' for ' + innerStringRepresentation;320 function yFactory() {321 return outerThenableFactory(innerThenableFactory(sentinel));322 }323 testCallingResolvePromiseFulfillsWith(yFactory, stringRepresentation, sentinel);324 });325 Object.keys(rejectedThen).forEach(function (innerStringRepresentation) {326 // @ts-ignore327 const innerThenableFactory = rejectedThen[innerStringRepresentation];328 const stringRepresentation = outerStringRepresentation + ' for ' + innerStringRepresentation;329 function yFactory() {330 return outerThenableFactory(innerThenableFactory(sentinel));331 }332 testCallingResolvePromiseRejectsWith(yFactory, stringRepresentation, sentinel);333 });334 });335 });336 });337 describe('2.3.3.3.2: If/when `rejectPromise` is called with reason `r`, reject `promise` with `r`', function () {338 testCallingRejectPromiseRejectsWith(undefined, '`undefined`');339 testCallingRejectPromiseRejectsWith(null, '`null`');340 testCallingRejectPromiseRejectsWith(false, '`false`');341 testCallingRejectPromiseRejectsWith(0, '`0`');342 testCallingRejectPromiseRejectsWith(new Error(), 'an error');343 testCallingRejectPromiseRejectsWith(344 (function () {345 var error = new Error();346 delete error.stack;347 return error;348 })(),349 'an error without a stack'350 );351 testCallingRejectPromiseRejectsWith(new Date(), 'a date');352 testCallingRejectPromiseRejectsWith({}, 'an object');353 testCallingRejectPromiseRejectsWith({then: function () {}}, 'an always-pending thenable');354 testCallingRejectPromiseRejectsWith(resolved(dummy), 'a fulfilled promise');355 testCallingRejectPromiseRejectsWith(356 rejected(dummy).catch(() => {}),357 'a rejected promise'358 );359 });360 describe(361 '2.3.3.3.3: If both `resolvePromise` and `rejectPromise` are called, or multiple calls to the same ' +362 'argument are made, the first call takes precedence, and any further calls are ignored.',363 function () {364 describe('calling `resolvePromise` then `rejectPromise`, both synchronously', function () {365 function xFactory() {366 return {367 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {368 resolvePromise(sentinel);369 rejectPromise(other);370 },371 };372 }373 testPromiseResolution(xFactory, function (promise, done) {374 promise.then(function (value) {375 expect(value).toStrictEqual(sentinel);376 done();377 });378 });379 });380 describe('calling `resolvePromise` synchronously then `rejectPromise` asynchronously', function () {381 function xFactory() {382 return {383 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {384 resolvePromise(sentinel);385 setTimeout(function () {386 rejectPromise(other);387 }, 0);388 },389 };390 }391 testPromiseResolution(xFactory, function (promise, done) {392 promise.then(function (value) {393 expect(value).toStrictEqual(sentinel);394 done();395 });396 });397 });398 describe('calling `resolvePromise` then `rejectPromise`, both asynchronously', function () {399 function xFactory() {400 return {401 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {402 setTimeout(function () {403 resolvePromise(sentinel);404 }, 0);405 setTimeout(function () {406 rejectPromise(other);407 }, 0);408 },409 };410 }411 testPromiseResolution(xFactory, function (promise, done) {412 promise.then(function (value) {413 expect(value).toStrictEqual(sentinel);414 done();415 });416 });417 });418 describe(419 'calling `resolvePromise` with an asynchronously-fulfilled promise, then calling ' + '`rejectPromise`, both synchronously',420 function () {421 function xFactory() {422 var d = deferred();423 setTimeout(function () {424 d.resolve(sentinel);425 }, 50);426 return {427 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {428 resolvePromise(d.promise);429 rejectPromise(other);430 },431 };432 }433 testPromiseResolution(xFactory, function (promise, done) {434 promise.then(function (value) {435 expect(value).toStrictEqual(sentinel);436 done();437 });438 });439 }440 );441 describe(442 'calling `resolvePromise` with an asynchronously-rejected promise, then calling ' + '`rejectPromise`, both synchronously',443 function () {444 function xFactory() {445 var d = deferred();446 setTimeout(function () {447 d.reject(sentinel);448 }, 50);449 return {450 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {451 resolvePromise(d.promise);452 rejectPromise(other);453 },454 };455 }456 testPromiseResolution(xFactory, function (promise, done) {457 promise.then(null, function (reason) {458 expect(reason).toStrictEqual(sentinel);459 done();460 });461 });462 }463 );464 describe('calling `rejectPromise` then `resolvePromise`, both synchronously', function () {465 function xFactory() {466 return {467 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {468 rejectPromise(sentinel);469 resolvePromise(other);470 },471 };472 }473 testPromiseResolution(xFactory, function (promise, done) {474 promise.then(null, function (reason) {475 expect(reason).toStrictEqual(sentinel);476 done();477 });478 });479 });480 describe('calling `rejectPromise` synchronously then `resolvePromise` asynchronously', function () {481 function xFactory() {482 return {483 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {484 rejectPromise(sentinel);485 setTimeout(function () {486 resolvePromise(other);487 }, 0);488 },489 };490 }491 testPromiseResolution(xFactory, function (promise, done) {492 promise.then(null, function (reason) {493 expect(reason).toStrictEqual(sentinel);494 done();495 });496 });497 });498 describe('calling `rejectPromise` then `resolvePromise`, both asynchronously', function () {499 function xFactory() {500 return {501 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {502 setTimeout(function () {503 rejectPromise(sentinel);504 }, 0);505 setTimeout(function () {506 resolvePromise(other);507 }, 0);508 },509 };510 }511 testPromiseResolution(xFactory, function (promise, done) {512 promise.then(null, function (reason) {513 expect(reason).toStrictEqual(sentinel);514 done();515 });516 });517 });518 describe('calling `resolvePromise` twice synchronously', function () {519 function xFactory() {520 return {521 then: function (resolvePromise: (value: any) => void) {522 resolvePromise(sentinel);523 resolvePromise(other);524 },525 };526 }527 testPromiseResolution(xFactory, function (promise, done) {528 promise.then(function (value) {529 expect(value).toStrictEqual(sentinel);530 done();531 });532 });533 });534 describe('calling `resolvePromise` twice, first synchronously then asynchronously', function () {535 function xFactory() {536 return {537 then: function (resolvePromise: (value: any) => void) {538 resolvePromise(sentinel);539 setTimeout(function () {540 resolvePromise(other);541 }, 0);542 },543 };544 }545 testPromiseResolution(xFactory, function (promise, done) {546 promise.then(function (value) {547 expect(value).toStrictEqual(sentinel);548 done();549 });550 });551 });552 describe('calling `resolvePromise` twice, both times asynchronously', function () {553 function xFactory() {554 return {555 then: function (resolvePromise: (value: any) => void) {556 setTimeout(function () {557 resolvePromise(sentinel);558 }, 0);559 setTimeout(function () {560 resolvePromise(other);561 }, 0);562 },563 };564 }565 testPromiseResolution(xFactory, function (promise, done) {566 promise.then(function (value) {567 expect(value).toStrictEqual(sentinel);568 done();569 });570 });571 });572 describe(573 'calling `resolvePromise` with an asynchronously-fulfilled promise, then calling it again, both ' + 'times synchronously',574 function () {575 function xFactory() {576 var d = deferred();577 setTimeout(function () {578 d.resolve(sentinel);579 }, 50);580 return {581 then: function (resolvePromise: (value: any) => void) {582 resolvePromise(d.promise);583 resolvePromise(other);584 },585 };586 }587 testPromiseResolution(xFactory, function (promise, done) {588 promise.then(function (value) {589 expect(value).toStrictEqual(sentinel);590 done();591 });592 });593 }594 );595 describe(596 'calling `resolvePromise` with an asynchronously-rejected promise, then calling it again, both ' + 'times synchronously',597 function () {598 function xFactory() {599 var d = deferred();600 setTimeout(function () {601 d.reject(sentinel);602 }, 50);603 return {604 then: function (resolvePromise: (value: any) => void) {605 resolvePromise(d.promise);606 resolvePromise(other);607 },608 };609 }610 testPromiseResolution(xFactory, function (promise, done) {611 promise.then(null, function (reason) {612 expect(reason).toStrictEqual(sentinel);613 done();614 });615 });616 }617 );618 describe('calling `rejectPromise` twice synchronously', function () {619 function xFactory() {620 return {621 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {622 rejectPromise(sentinel);623 rejectPromise(other);624 },625 };626 }627 testPromiseResolution(xFactory, function (promise, done) {628 promise.then(null, function (reason) {629 expect(reason).toStrictEqual(sentinel);630 done();631 });632 });633 });634 describe('calling `rejectPromise` twice, first synchronously then asynchronously', function () {635 function xFactory() {636 return {637 then: function (_: undefined, rejectPromise: (reason: any) => void) {638 rejectPromise(sentinel);639 setTimeout(function () {640 rejectPromise(other);641 }, 0);642 },643 };644 }645 testPromiseResolution(xFactory, function (promise, done) {646 promise.then(null, function (reason) {647 expect(reason).toStrictEqual(sentinel);648 done();649 });650 });651 });652 describe('calling `rejectPromise` twice, both times asynchronously', function () {653 function xFactory() {654 return {655 then: function (_: undefined, rejectPromise: (reason: any) => void) {656 setTimeout(function () {657 rejectPromise(sentinel);658 }, 0);659 setTimeout(function () {660 rejectPromise(other);661 }, 0);662 },663 };664 }665 testPromiseResolution(xFactory, function (promise, done) {666 promise.then(null, function (reason) {667 expect(reason).toStrictEqual(sentinel);668 done();669 });670 });671 });672 describe('saving and abusing `resolvePromise` and `rejectPromise`', function () {673 var savedResolvePromise: (value: any) => void | null, savedRejectPromise: (reason: any) => void | null;674 function xFactory() {675 return {676 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {677 savedResolvePromise = resolvePromise;678 savedRejectPromise = rejectPromise;679 },680 };681 }682 beforeEach(function () {683 // @ts-ignore684 savedResolvePromise = null;685 // @ts-ignore686 savedRejectPromise = null;687 });688 testPromiseResolution(xFactory, function (promise, done) {689 var timesFulfilled = 0;690 var timesRejected = 0;691 promise.then(692 function () {693 ++timesFulfilled;694 },695 function () {696 ++timesRejected;697 }698 );699 // @ts-ignore700 if (savedResolvePromise && savedRejectPromise) {701 savedResolvePromise(dummy);702 savedResolvePromise(dummy);703 savedRejectPromise(dummy);704 savedRejectPromise(dummy);705 }706 setTimeout(function () {707 savedResolvePromise(dummy);708 savedResolvePromise(dummy);709 savedRejectPromise(dummy);710 savedRejectPromise(dummy);711 }, 50);712 setTimeout(function () {713 expect(timesFulfilled).toBe(1);714 expect(timesRejected).toBe(0);715 done();716 }, 100);717 });718 });719 }720 );721 describe('2.3.3.3.4: If calling `then` throws an exception `e`,', function () {722 describe('2.3.3.3.4.1: If `resolvePromise` or `rejectPromise` have been called, ignore it.', function () {723 describe('`resolvePromise` was called with a non-thenable', function () {724 function xFactory() {725 return {726 then: function (resolvePromise: (value: any) => void) {727 resolvePromise(sentinel);728 throw other;729 },730 };731 }732 testPromiseResolution(xFactory, function (promise, done) {733 promise.then(function (value) {734 expect(value).toStrictEqual(sentinel);735 done();736 });737 });738 });739 describe('`resolvePromise` was called with an asynchronously-fulfilled promise', function () {740 function xFactory() {741 var d = deferred();742 setTimeout(function () {743 d.resolve(sentinel);744 }, 50);745 return {746 then: function (resolvePromise: (value: any) => void) {747 resolvePromise(d.promise);748 throw other;749 },750 };751 }752 testPromiseResolution(xFactory, function (promise, done) {753 promise.then(function (value) {754 expect(value).toStrictEqual(sentinel);755 done();756 });757 });758 });759 describe('`resolvePromise` was called with an asynchronously-rejected promise', function () {760 function xFactory() {761 var d = deferred();762 setTimeout(function () {763 d.reject(sentinel);764 }, 50);765 return {766 then: function (resolvePromise: (value: any) => void) {767 resolvePromise(d.promise);768 throw other;769 },770 };771 }772 testPromiseResolution(xFactory, function (promise, done) {773 promise.then(null, function (reason) {774 expect(reason).toStrictEqual(sentinel);775 done();776 });777 });778 });779 describe('`rejectPromise` was called', function () {780 function xFactory() {781 return {782 then: function (_: undefined, rejectPromise: (reason: any) => void) {783 rejectPromise(sentinel);784 throw other;785 },786 };787 }788 testPromiseResolution(xFactory, function (promise, done) {789 promise.then(null, function (reason) {790 expect(reason).toStrictEqual(sentinel);791 done();792 });793 });794 });795 describe('`resolvePromise` then `rejectPromise` were called', function () {796 function xFactory() {797 return {798 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {799 resolvePromise(sentinel);800 rejectPromise(other);801 throw other;802 },803 };804 }805 testPromiseResolution(xFactory, function (promise, done) {806 promise.then(function (value) {807 expect(value).toStrictEqual(sentinel);808 done();809 });810 });811 });812 describe('`rejectPromise` then `resolvePromise` were called', function () {813 function xFactory() {814 return {815 then: function (resolvePromise: (value: any) => void, rejectPromise: (reason: any) => void) {816 rejectPromise(sentinel);817 resolvePromise(other);818 throw other;819 },820 };821 }822 testPromiseResolution(xFactory, function (promise, done) {823 promise.then(null, function (reason) {824 expect(reason).toStrictEqual(sentinel);825 done();826 });827 });828 });829 });830 describe('2.3.3.3.4.2: Otherwise, reject `promise` with `e` as the reason.', function () {831 describe('straightforward case', function () {832 function xFactory() {833 return {834 then: function () {835 throw sentinel;836 },837 };838 }839 testPromiseResolution(xFactory, function (promise, done) {840 promise.then(null, function (reason) {841 expect(reason).toStrictEqual(sentinel);842 done();843 });844 });845 });846 describe('`resolvePromise` is called asynchronously before the `throw`', function () {847 function xFactory() {848 return {849 then: function (resolvePromise: (value: any) => void) {850 setTimeout(function () {851 resolvePromise(other);852 }, 0);853 throw sentinel;854 },855 };856 }857 testPromiseResolution(xFactory, function (promise, done) {858 promise.then(null, function (reason) {859 expect(reason).toStrictEqual(sentinel);860 done();861 });862 });863 });864 describe('`rejectPromise` is called asynchronously before the `throw`', function () {865 function xFactory() {866 return {867 then: function (_: undefined, rejectPromise: (reason: any) => void) {868 setTimeout(function () {869 rejectPromise(other);870 }, 0);871 throw sentinel;872 },873 };874 }875 testPromiseResolution(xFactory, function (promise, done) {876 promise.then(null, function (reason) {877 expect(reason).toStrictEqual(sentinel);878 done();879 });880 });881 });882 });883 });...
Using AI Code Generation
1var wptService = require('./wptService');2wptService.rejectPromise()3 .then(function (data) {4 console.log(data);5 })6 .catch(function (err) {7 console.log(err);8 });9wptService.resolvePromise()10 .then(function (data) {11 console.log(data);12 })13 .catch(function (err) {14 console.log(err);15 });16wptService.rejectPromiseWithDelay()17 .then(function (data) {18 console.log(data);19 })20 .catch(function (err) {21 console.log(err);22 });23wptService.resolvePromiseWithDelay()24 .then(function (data) {25 console.log(data);26 })27 .catch(function (err) {28 console.log(err);29 });30var Promise = require('bluebird');31var wptService = {32 rejectPromise: function () {33 return new Promise(function (resolve, reject) {34 reject('rejected promise');35 });36 },37 resolvePromise: function () {38 return new Promise(function (resolve, reject) {39 resolve('resolved promise');40 });41 },42 rejectPromiseWithDelay: function () {43 return new Promise(function (resolve, reject) {44 setTimeout(function () {45 reject('rejected promise with delay');46 }, 1000);47 });48 },49 resolvePromiseWithDelay: function () {50 return new Promise(function (resolve, reject) {51 setTimeout(function () {52 resolve('resolved promise with delay');53 }, 1000);54 });55 }56};57module.exports = wptService;
Using AI Code Generation
1var wpt = require('wpt.js');2var options = {3};4wpt.rejectPromise(options).then(function (data) {5 console.log('Test Finished');6 console.log(data);7}).catch(function (error) {8 console.log('Test Failed');9 console.log(error);10});11The MIT License (MIT)
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit.rejectPromise('test error message');3var wptoolkit = require('wptoolkit');4wptoolkit.rejectPromise('test error message').catch(function(err) {5 console.log(err);6});7var wptoolkit = require('wptoolkit');8wptoolkit.rejectPromise('test error message').then(function() {9 console.log('test 3');10}).catch(function(err) {11 console.log(err);12});13var wptoolkit = require('wptoolkit');14wptoolkit.rejectPromise('test error message').then(function() {15 console.log('test 4');16}).catch(function(err) {17 console.log(err);18}).then(function() {19 console.log('test 4.1');20});21var wptoolkit = require('wptoolkit');22wptoolkit.rejectPromise('test error message').then(function() {23 console.log('test 5');24}).catch(function(err) {25 console.log(err);26}).then(function() {27 console.log('test 5.1');28}).catch(function(err) {29 console.log(err);30});31var wptoolkit = require('wptoolkit');32wptoolkit.rejectPromise('test error message').then(function() {33 console.log('test 6');34}).catch(function(err) {35 console.log(err);36}).then(function() {37 console.log('test 6.1');38}).catch(function(err) {39 console.log(err);40}).then(function() {41 console.log('test 6.2');42});43var wptoolkit = require('wptoolkit');44wptoolkit.rejectPromise('test error message').then(function() {45 console.log('test 7');46}).catch(function(err) {47 console.log(err);48}).then(function() {49 console.log('test 7.1');50}).catch(function(err) {51 console.log(err);
Using AI Code Generation
1var wpt = require('wpt-api');2wpt.rejectPromise(1, 2, 3).then(function (data) {3 console.log(data);4}, function (error) {5 console.log(error);6});7var wpt = require('wpt-api');8wpt.rejectPromise(1, 2, 3).then(function (data) {9 console.log(data);10}, function (error) {11 console.log(error);12});13var wpt = require('wpt-api');14wpt.rejectPromise(1, 2, 3).then(function (data) {15 console.log(data);16}, function (error) {17 console.log(error);18});19var wpt = require('wpt-api');20wpt.rejectPromise(1, 2, 3).then(function (data) {21 console.log(data);22}, function (error) {23 console.log(error);24});25var wpt = require('wpt-api');26wpt.rejectPromise(1, 2, 3).then(function (data) {27 console.log(data);28}, function (error) {29 console.log(error);30});31var wpt = require('wpt-api');32wpt.rejectPromise(1, 2, 3).then(function (data) {33 console.log(data);34}, function (error) {35 console.log(error);36});37var wpt = require('wpt-api');38wpt.rejectPromise(1, 2, 3).then(function (data) {39 console.log(data);40}, function (error) {41 console.log(error);42});
Using AI Code Generation
1wpt.rejectPromise(300000)2.then(function(result) {3 console.log(result);4})5.catch(function(err) {6 console.log(err);7});8wpt.rejectPromise(300000, "Test is still running after 5 minutes")9.then(function(result) {10 console.log(result);11})12.catch(function(err) {13 console.log(err);14});15wpt.rejectPromise(300000, "Test is still running after 5 minutes", 10000)16.then(function(result) {17 console.log(result);18})19.catch(function(err) {20 console.log(err);21});22wpt.rejectPromise(300000, "Test is still running after 5 minutes", 10000, 10000)23.then(function(result) {24 console.log(result);25})
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!