How to use promise1 method in wpt

Best JavaScript code snippet using wpt

promises-revision.js

Source:promises-revision.js Github

copy

Full Screen

1// to perform asynchronous operation2// let p1 = Promise.resolve("p1 data");3// let p2 = Promise.resolve("p2");4// console.log(p1, p2);5// console.log("starting");6// setTimeout(() => {7// console.log("set time out");8// }, 0);9// Promise.resolve(1)10// .then(() => console.log("promise1 resol"))11// .catch((err) => console.log("catching 1 promise"));12// Promise.resolve(1).then(() => console.log("promise2"));13// Promise.resolve(1).then(() => console.log("promise3"));14// Promise.resolve(1).then(() => console.log("promise4"));15// Promise.resolve(1).then(() => console.log("promise1"));16// Promise.resolve(1).then(() => console.log("promise2"));17// Promise.resolve(1).then(() => console.log("promise3"));18// Promise.resolve(1).then(() => console.log("promise4"));19// Promise.resolve(1).then(() => console.log("promise1"));20// Promise.resolve(1).then(() => console.log("promise2"));21// Promise.resolve(1).then(() => console.log("promise3"));22// Promise.resolve(1).then(() => console.log("promise4"));23// Promise.resolve(1).then(() => console.log("promise1"));24// Promise.resolve(1).then(() => console.log("promise2"));25// Promise.resolve(1).then(() => console.log("promise3"));26// Promise.resolve(1).then(() => console.log("promise4"));27// Promise.resolve(1).then(() => console.log("promise1"));28// Promise.resolve(1).then(() => console.log("promise2"));29// Promise.resolve(1).then(() => console.log("promise3"));30// Promise.resolve(1).then(() => console.log("promise4"));31// Promise.resolve(1).then(() => console.log("promise1"));32// Promise.resolve(1).then(() => console.log("promise2"));33// Promise.resolve(1).then(() => console.log("promise3"));34// Promise.resolve(1).then(() => console.log("promise4"));35// Promise.resolve(1).then(() => console.log("promise1"));36// Promise.resolve(1).then(() => console.log("promise2"));37// Promise.resolve(1).then(() => console.log("promise3"));38// Promise.resolve(1).then(() => console.log("promise4"));39// Promise.resolve(1).then(() => console.log("promise1"));40// Promise.resolve(1).then(() => console.log("promise2"));41// Promise.resolve(1).then(() => console.log("promise3"));42// Promise.resolve(1).then(() => console.log("promise4"));43// Promise.resolve(1).then(() => console.log("promise1"));44// Promise.resolve(1).then(() => console.log("promise2"));45// Promise.resolve(1).then(() => console.log("promise3"));46// Promise.resolve(1).then(() => console.log("promise4"));47// Promise.resolve(1).then(() => console.log("promise1"));48// Promise.resolve(1).then(() => console.log("promise2"));49// Promise.resolve(1).then(() => console.log("promise3"));50// Promise.resolve(1).then(() => console.log("promise4"));51// Promise.resolve(1).then(() => console.log("promise1"));52// Promise.resolve(1).then(() => console.log("promise2"));53// Promise.resolve(1).then(() => console.log("promise3"));54// Promise.resolve(1).then(() => console.log("promise4"));55// Promise.resolve(1).then(() => console.log("promise1"));56// Promise.resolve(1).then(() => console.log("promise2"));57// Promise.resolve(1).then(() => console.log("promise3"));58// Promise.resolve(1).then(() => console.log("promise4"));59// Promise.resolve(1).then(() => console.log("promise1"));60// Promise.resolve(1).then(() => console.log("promise2"));61// Promise.resolve(1).then(() => console.log("promise3"));62// Promise.resolve(1).then(() => console.log("promise4"));63// Promise.resolve(1).then(() => console.log("promise1"));64// Promise.resolve(1).then(() => console.log("promise2"));65// Promise.resolve(1).then(() => console.log("promise3"));66// Promise.resolve(1).then(() => console.log("promise4"));67// Promise.resolve(1).then(() => console.log("promise1"));68// Promise.resolve(1).then(() => console.log("promise2"));69// Promise.resolve(1).then(() => console.log("promise3"));70// Promise.resolve(1).then(() => console.log("promise4"));71// Promise.resolve(1).then(() => console.log("promise1"));72// Promise.resolve(1).then(() => console.log("promise2"));73// Promise.resolve(1).then(() => console.log("promise3"));74// Promise.resolve(1).then(() => console.log("promise4"));75// Promise.resolve(1).then(() => console.log("promise1"));76// Promise.resolve(1).then(() => console.log("promise2"));77// Promise.resolve(1).then(() => console.log("promise3"));78// Promise.resolve(1).then(() => console.log("promise4"));79// Promise.resolve(1).then(() => console.log("promise1"));80// Promise.resolve(1).then(() => console.log("promise2"));81// Promise.resolve(1).then(() => console.log("promise3"));82// Promise.resolve(1).then(() => console.log("promise4"));83// Promise.resolve(1).then(() => console.log("promise1"));84// Promise.resolve(1).then(() => console.log("promise2"));85// Promise.resolve(1).then(() => console.log("promise3"));86// Promise.resolve(1).then(() => console.log("promise4"));87// Promise.resolve(1).then(() => console.log("promise1"));88// Promise.resolve(1).then(() => console.log("promise2"));89// Promise.resolve(1).then(() => console.log("promise3"));90// Promise.resolve(1).then(() => console.log("promise4"));91// Promise.resolve(1).then(() => console.log("promise1"));92// Promise.resolve(1).then(() => console.log("promise2"));93// Promise.resolve(1).then(() => console.log("promise3"));94// Promise.resolve(1).then(() => console.log("promise4"));95// Promise.resolve(1).then(() => console.log("promise1"));96// Promise.resolve(1).then(() => console.log("promise2"));97// Promise.resolve(1).then(() => console.log("promise3"));98// Promise.resolve(1).then(() => console.log("promise4"));99// Promise.resolve(1).then(() => console.log("promise1"));100// Promise.resolve(1).then(() => console.log("promise2"));101// Promise.resolve(1).then(() => console.log("promise3"));102// Promise.resolve(1).then(() => console.log("promise4"));103// Promise.resolve(1).then(() => console.log("promise1"));104// Promise.resolve(1).then(() => console.log("promise2"));105// Promise.resolve(1).then(() => console.log("promise3"));106// Promise.resolve(1).then(() => console.log("promise4"));107// Promise.resolve(1).then(() => console.log("promise1"));108// Promise.resolve(1).then(() => console.log("promise2"));109// Promise.resolve(1).then(() => console.log("promise3"));110// Promise.resolve(1).then(() => console.log("promise4"));111// Promise.resolve(1).then(() => console.log("promise1"));112// Promise.resolve(1).then(() => console.log("promise2"));113// Promise.resolve(1).then(() => console.log("promise3"));114// Promise.resolve(1).then(() => console.log("promise4"));115// Promise.resolve(1).then(() => console.log("promise1"));116// Promise.resolve(1).then(() => console.log("promise2"));117// Promise.resolve(1).then(() => console.log("promise3"));118// Promise.resolve(1).then(() => console.log("promise4"));119// Promise.resolve(1).then(() => console.log("promise1"));120// Promise.resolve(1).then(() => console.log("promise2"));121// Promise.resolve(1).then(() => console.log("promise3"));122// Promise.resolve(1).then(() => console.log("promise4"));123// Promise.resolve(1).then(() => console.log("promise1"));124// Promise.resolve(1).then(() => console.log("promise2"));125// Promise.resolve(1).then(() => console.log("promise3"));126// Promise.resolve(1).then(() => console.log("promise4"));127// Promise.resolve(1).then(() => console.log("promise1"));128// Promise.resolve(1).then(() => console.log("promise2"));129// Promise.resolve(1).then(() => console.log("promise3"));130// Promise.resolve(1).then(() => console.log("promise4"));131// Promise.resolve(1).then(() => console.log("promise1"));132// Promise.resolve(1).then(() => console.log("promise2"));133// Promise.resolve(1).then(() => console.log("promise3"));134// Promise.resolve(1).then(() => console.log("promise4"));135// Promise.resolve(1).then(() => console.log("promise1"));136// Promise.resolve(1).then(() => console.log("promise2"));137// Promise.resolve(1).then(() => console.log("promise3"));138// Promise.resolve(1).then(() => console.log("promise4"));139// Promise.resolve(1).then(() => console.log("promise1"));140// Promise.resolve(1).then(() => console.log("promise2"));141// Promise.resolve(1).then(() => console.log("promise3"));142// Promise.resolve(1).then(() => console.log("promise4"));143// Promise.resolve(1).then(() => console.log("promise1"));144// Promise.resolve(1).then(() => console.log("promise2"));145// Promise.resolve(1).then(() => console.log("promise3"));146// Promise.resolve(1).then(() => console.log("promise4"));147// Promise.resolve(1).then(() => console.log("promise1"));148// Promise.resolve(1).then(() => console.log("promise2"));149// Promise.resolve(1).then(() => console.log("promise3"));150// Promise.resolve(1).then(() => console.log("promise4"));151// Promise.resolve(1).then(() => console.log("promise1"));152// Promise.resolve(1).then(() => console.log("promise2"));153// Promise.resolve(1).then(() => console.log("promise3"));154// Promise.resolve(1).then(() => console.log("promise4"));155// Promise.resolve(1).then(() => console.log("promise1"));156// Promise.resolve(1).then(() => console.log("promise2"));157// Promise.resolve(1).then(() => console.log("promise3"));158// Promise.resolve(1).then(() => console.log("promise4"));159// Promise.resolve(1).then(() => console.log("promise1"));160// Promise.resolve(1).then(() => console.log("promise2"));161// Promise.resolve(1).then(() => console.log("promise3"));162// Promise.resolve(1).then(() => console.log("promise4"));163// Promise.resolve(1).then(() => console.log("promise1"));164// Promise.resolve(1).then(() => console.log("promise2"));165// Promise.resolve(1).then(() => console.log("promise3"));166// Promise.resolve(1).then(() => console.log("promise4"));167// Promise.resolve(1).then(() => console.log("promise1"));168// Promise.resolve(1).then(() => console.log("promise2"));169// Promise.resolve(1).then(() => console.log("promise3"));170// Promise.resolve(1).then(() => console.log("promise4"));171// Promise.resolve(1).then(() => console.log("promise1"));172// Promise.resolve(1).then(() => console.log("promise2"));173// Promise.resolve(1).then(() => console.log("promise3"));174// Promise.resolve(1).then(() => console.log("promise4"));175// Promise.resolve(1).then(() => console.log("promise1"));176// Promise.resolve(1).then(() => console.log("promise2"));177// Promise.resolve(1).then(() => console.log("promise3"));178// Promise.resolve(1).then(() => console.log("promise4"));179// Promise.resolve(1).then(() => console.log("promise1"));180// Promise.resolve(1).then(() => console.log("promise2"));181// Promise.resolve(1).then(() => console.log("promise3"));182// Promise.resolve(1).then(() => console.log("promise4"));183// Promise.resolve(1).then(() => console.log("promise1"));184// Promise.resolve(1).then(() => console.log("promise2"));185// Promise.resolve(1).then(() => console.log("promise3"));186// Promise.resolve(1).then(() => console.log("promise4"));187// Promise.resolve(1).then(() => console.log("promise1"));188// Promise.resolve(1).then(() => console.log("promise2"));189// Promise.resolve(1).then(() => console.log("promise3"));190// Promise.resolve(1).then(() => console.log("promise4"));191// Promise.resolve(1).then(() => console.log("promise1"));192// Promise.resolve(1).then(() => console.log("promise2"));193// Promise.resolve(1).then(() => console.log("promise3"));194// Promise.resolve(1).then(() => console.log("promise4"));195// Promise.resolve(1).then(() => console.log("promise1"));196// Promise.resolve(1).then(() => console.log("promise2"));197// Promise.resolve(1).then(() => console.log("promise3"));198// Promise.resolve(1).then(() => console.log("promise4"));199// Promise.resolve(1).then(() => console.log("promise1"));200// Promise.resolve(1).then(() => console.log("promise2"));201// Promise.resolve(1).then(() => console.log("promise3"));202// Promise.resolve(1).then(() => console.log("promise4"));203// Promise.resolve(1).then(() => console.log("promise1"));204// Promise.resolve(1).then(() => console.log("promise2"));205// Promise.resolve(1).then(() => console.log("promise3"));206// Promise.resolve(1).then(() => console.log("promise4"));207// Promise.resolve(1).then(() => console.log("promise1"));208// Promise.resolve(1).then(() => console.log("promise2"));209// Promise.resolve(1).then(() => console.log("promise3"));210// Promise.resolve(1).then(() => console.log("promise4"));211// Promise.resolve(1).then(() => console.log("promise1"));212// Promise.resolve(1).then(() => console.log("promise2"));213// Promise.resolve(1).then(() => console.log("promise3"));214// Promise.resolve(1).then(() => console.log("promise4"));215// Promise.resolve(1).then(() => console.log("promise1"));216// Promise.resolve(1).then(() => console.log("promise2"));217// Promise.resolve(1).then(() => console.log("promise3"));218// Promise.resolve(1).then(() => console.log("promise4"));219// Promise.resolve(1).then(() => console.log("promise1"));220// Promise.resolve(1).then(() => console.log("promise2"));221// Promise.resolve(1).then(() => console.log("promise3"));222// Promise.resolve(1).then(() => console.log("promise4"));223// Promise.resolve(1).then(() => console.log("promise1"));224// Promise.resolve(1).then(() => console.log("promise2"));225// Promise.resolve(1).then(() => console.log("promise3"));226// Promise.resolve(1).then(() => console.log("promise4"));227// Promise.resolve(1).then(() => console.log("promise1"));228// Promise.resolve(1).then(() => console.log("promise2"));229// Promise.resolve(1).then(() => console.log("promise3"));230// Promise.resolve(1).then(() => console.log("promise4"));231// Promise.resolve(1).then(() => console.log("promise1"));232// Promise.resolve(1).then(() => console.log("promise2"));233// Promise.resolve(1).then(() => console.log("promise3"));234// Promise.resolve(1).then(() => console.log("promise4"));235// Promise.resolve(1).then(() => console.log("promise1"));236// Promise.resolve(1).then(() => console.log("promise2"));237// Promise.resolve(1).then(() => console.log("promise3"));238// Promise.resolve(1).then(() => console.log("promise4"));239// Promise.resolve(1).then(() => console.log("promise1"));240// Promise.resolve(1).then(() => console.log("promise2"));241// Promise.resolve(1).then(() => console.log("promise3"));242// Promise.resolve(1).then(() => console.log("promise4"));243// Promise.resolve(1).then(() => console.log("promise1"));244// Promise.resolve(1).then(() => console.log("promise2"));245// Promise.resolve(1).then(() => console.log("promise3"));246// Promise.resolve(1).then(() => console.log("promise4"));247// Promise.resolve(1).then(() => console.log("promise1"));248// Promise.resolve(1).then(() => console.log("promise2"));249// Promise.resolve(1).then(() => console.log("promise3"));250// Promise.resolve(1).then(() => console.log("promise4"));251// Promise.resolve(1).then(() => console.log("promise1"));252// Promise.resolve(1).then(() => console.log("promise2"));253// Promise.resolve(1).then(() => console.log("promise3"));254// Promise.resolve(1).then(() => console.log("promise4"));255// Promise.resolve(1).then(() => console.log("promise1"));256// Promise.resolve(1).then(() => console.log("promise2"));257// Promise.resolve(1).then(() => console.log("promise3"));258// Promise.resolve(1).then(() => console.log("promise4"));259// Promise.resolve(1).then(() => console.log("promise1"));260// Promise.resolve(1).then(() => console.log("promise2"));261// Promise.resolve(1).then(() => console.log("promise3"));262// Promise.resolve(1).then(() => console.log("promise4"));263// Promise.resolve(1).then(() => console.log("promise1"));264// Promise.resolve(1).then(() => console.log("promise2"));265// Promise.resolve(1).then(() => console.log("promise3"));266// Promise.resolve(1).then(() => console.log("promise4"));267// Promise.resolve(1).then(() => console.log("promise1"));268// Promise.resolve(1).then(() => console.log("promise2"));269// Promise.resolve(1).then(() => console.log("promise3"));270// Promise.resolve(1).then(() => console.log("promise4"));271// Promise.resolve(1).then(() => console.log("promise1"));272// Promise.resolve(1).then(() => console.log("promise2"));273// Promise.resolve(1).then(() => console.log("promise3"));274// Promise.resolve(1).then(() => console.log("promise4"));275// Promise.resolve(1).then(() => console.log("promise1"));276// Promise.resolve(1).then(() => console.log("promise2"));277// Promise.resolve(1).then(() => console.log("promise3"));278// Promise.resolve(1).then(() => console.log("promise4"));279// Promise.resolve(1).then(() => console.log("promise1"));280// Promise.resolve(1).then(() => console.log("promise2"));281// Promise.resolve(1).then(() => console.log("promise3"));282// Promise.resolve(1).then(() => console.log("promise4"));283// Promise.resolve(1).then(() => console.log("promise1"));284// Promise.resolve(1).then(() => console.log("promise2"));285// Promise.resolve(1).then(() => console.log("promise3"));286// Promise.resolve(1).then(() => console.log("promise4"));287// Promise.resolve(1).then(() => console.log("promise1"));288// Promise.resolve(1).then(() => console.log("promise2"));289// Promise.resolve(1).then(() => console.log("promise3"));290// Promise.resolve(1).then(() => console.log("promise4"));291// Promise.resolve(1).then(() => console.log("promise1"));292// Promise.resolve(1).then(() => console.log("promise2"));293// Promise.resolve(1).then(() => console.log("promise3"));294// Promise.resolve(1).then(() => console.log("promise4"));295// Promise.resolve(1).then(() => console.log("promise1"));296// Promise.resolve(1).then(() => console.log("promise2"));297// Promise.resolve(1).then(() => console.log("promise3"));298// Promise.resolve(1).then(() => console.log("promise4"));299// Promise.resolve(1).then(() => console.log("promise1"));300// Promise.resolve(1).then(() => console.log("promise2"));301// Promise.resolve(1).then(() => console.log("promise3"));302// Promise.resolve(1).then(() => console.log("promise4"));303// Promise.resolve(1).then(() => console.log("promise1"));304// Promise.resolve(1).then(() => console.log("promise2"));305// Promise.resolve(1).then(() => console.log("promise3"));306// Promise.resolve(1).then(() => console.log("promise4"));307// Promise.resolve(1).then(() => console.log("promise1"));308// Promise.resolve(1).then(() => console.log("promise2"));309// Promise.resolve(1).then(() => console.log("promise3"));310// Promise.resolve(1).then(() => console.log("promise4"));311// Promise.resolve(1).then(() => console.log("promise1"));312// Promise.resolve(1).then(() => console.log("promise2"));313// Promise.resolve(1).then(() => console.log("promise3"));314// Promise.resolve(1).then(() => console.log("promise4"));315// Promise.resolve(1).then(() => console.log("promise1"));316// Promise.resolve(1).then(() => console.log("promise2"));317// Promise.resolve(1).then(() => console.log("promise3"));318// Promise.resolve(1).then(() => console.log("promise4"));319// Promise.resolve(1).then(() => console.log("promise1"));320// Promise.resolve(1).then(() => console.log("promise2"));321// Promise.reject(1)322// .then(() => console.log("promise3"))323// .catch((err) => console.log("catching"));324// Promise.resolve(1).then(() =>325// console.log("promise4fbsjafbkajsbfkasabfkakjfkjabbfka")326// );327// Promise.resolve(1).then(() => console.log("promise1 ----vasanth"));328// Promise.resolve(1).then(() => console.log("promise2"));329// Promise.resolve(1).then(() => console.log("promise3"));330// Promise.resolve(1).then(() => console.log("promise4"));331// Promise.resolve(1).then(() => console.log("promise1"));332// Promise.resolve(1).then(() => console.log("promise2"));333// Promise.resolve(1).then(() => console.log("promise3"));334// Promise.resolve(1).then(() => console.log("promise4"));335// Promise.resolve(1).then(() => console.log("promise1"));336// Promise.resolve(1).then(() => console.log("promise2"));337// Promise.resolve(1).then(() => console.log("promise3"));338// Promise.resolve(1).then(() => console.log("promise4"));339// Promise.resolve(1).then(() => console.log("promise1"));340// Promise.resolve(1).then(() => console.log("promise2"));341// Promise.resolve(1).then(() => console.log("promise3"));342// Promise.resolve(1).then(() => console.log("promise4"));343// console.log("end");344// classes -> Multi paradigm programming language345// OOPs -> Object Oriented Programming system346// functional programming347// class == function348// class is a syntactic sugar of function349// async await is a syntactic of promise350// function Person(name, age) {351// this.name = name;352// this.age = age;353// this.getAge = function () {354// return this.age;355// };356// console.log(this);357// // return this; default return this358// }359// const vasanth = new Person("vasanth", 20);360// console.log("this return", vasanth);361// const Hema = new Person("Hema", 6);362// const Amit = new Person("Amit", 2);363//364// class Person {365// constructor(name, age) {366// this.name = name;367// this.age = age;368// }369// // getter370// get fullName() {371// return this.name + " kumar";372// }373// set setFullName(name) {374// this.name = name;375// }376// getAge() {377// return this.age;378// }379// }380// let vasanth = new Person("vasanth", 20);381// console.log(vasanth.age, vasanth.fullName);382// vasanth.setFullName = "Rajesh";383// console.log(vasanth.fullName);384// Person();385// class Person1 {386// constructor() {387// console.log("person in class");388// }389// }390// new Person1();391// function Person() {392// console.log("person in fn ");393// }394// function declarations are hoisted but classes are not hoisted395// class -> it is a blue print396// objects -> instance of class or real time entity397// class Human {398// constructor(name, age, gender) {399// this.name = name;400// this.age = age;401// this.gender = gender;402// }403// eat() {404// console.log("eating ");405// }406// sleep() {407// console.log("sleeping");408// }409// think() {410// // console.log("thinking");411// return "thinking";412// }413// }414// let vasanth = new Human("vasanth", 10, "Male");415// console.log(vasanth, vasanth.think());416// let Rani = new Human("rani", 14, "Female");417// class Car {418// constructor(model, color, brand, type) {419// this.model = model;420// this.color = color;421// this.brand = brand;422// this.type = type;423// }424// run() {425// console.log("running");426// }427// playSongs() {428// console.log("songs");429// }430// }431// let hondaCity = new Car("2022", "red", "honda", "sedan");432// let rangeaRover = new Car("2022", "red yellow", "tata", "SUV");433// inheritance434// class GrandParent {435// house() {436// console.log("house");437// }438// }439// class Parent extends GrandParent {440// car() {441// console.log("maruti espresso");442// }443// }444// class Child extends Parent {445// bike() {446// console.log("yamaha");447// }448// // polymorphism -> method overriding449// car() {450// console.log("audi");451// }452// }453// let vinayagam = new GrandParent();454// vinayagam.house();455// let vasanth = new Parent();456// let aadhitya = new Child();457// vasanth.car();458// aadhitya.car();459// // // aadhitya.bike();460// vasanth.house();461// aadhitya.house();`462// function Person(name) {463// this.name = name;464// this.getName = function () {465// return this.name;466// };467// this.num = 10;468// }469class Person {470 constructor(name) {471 this.name = name;472 }473 num = 10;474 getName() {475 return this.name;476 }477}478// let vasanth = new Person("vasanth");479// let anish = new Person("anish");480// console.log(vasanth.getName(), vasanth.num);481// class Laptop {482// constructor(ram, rom, brand, size = 15.4) {483// this.ram = ram;484// this.rom = rom;485// this.brand = brand;486// this.size = size;487// }488// }489// let macbookAir = new Laptop("4gb", 128, "apple", 13.3);490// let acer123 = new Laptop("4gb", 128, "acer");491// let dell = new Laptop("4gb", 128, "dell");492// console.log(macbookAir, acer123, dell);493// prototypical inheritance494// polyfill495// method496// fetch(), axios()497// jquery -> react, angular498// css advanced499// call, bind, apply500// currying501// ()()()502function getFact(num) {503 if (num == 1) {504 return 1;505 }506 return num * getFact(num - 1);507}508console.time();509console.log(getFact(50000000000));...

Full Screen

Full Screen

3.2.6.js

Source:3.2.6.js Github

copy

Full Screen

1"use strict";2var assert = require("assert");3var testFulfilled = require("./helpers/testThreeCases").testFulfilled;4var testRejected = require("./helpers/testThreeCases").testRejected;5var adapter = global.adapter;6var fulfilled = adapter.fulfilled;7var rejected = adapter.rejected;8var pending = adapter.pending;9var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it10var sentinel = { sentinel: "sentinel" }; // a sentinel fulfillment value to test for with strict equality11var other = { other: "other" }; // a value we don't want to be strict equal to12describe("3.2.6: `then` must return a promise: `promise2 = promise1.then(onFulfilled, onRejected)`", function () {13 specify("is a promise", function () {14 var promise1 = pending().promise;15 var promise2 = promise1.then();16 assert(typeof promise2 === "object" || typeof promise2 === "function");17 assert.notStrictEqual(promise2, null);18 assert.strictEqual(typeof promise2.then, "function");19 });20 describe("3.2.6.1: If either `onFulfilled` or `onRejected` returns a value that is not a promise, `promise2` " +21 "must be fulfilled with that value.", function () {22 function testValue(expectedValue, stringRepresentation) {23 describe("The value is " + stringRepresentation, function () {24 testFulfilled(dummy, function (promise1, done) {25 var promise2 = promise1.then(function onFulfilled() {26 return expectedValue;27 });28 promise2.then(function onPromise2Fulfilled(actualValue) {29 assert.strictEqual(actualValue, expectedValue);30 done();31 });32 });33 testRejected(dummy, function (promise1, done) {34 var promise2 = promise1.then(null, function onRejected() {35 return expectedValue;36 });37 promise2.then(function onPromise2Fulfilled(actualValue) {38 assert.strictEqual(actualValue, expectedValue);39 done();40 });41 });42 });43 }44 testValue(undefined, "`undefined`");45 testValue(null, "`null`");46 testValue(false, "`false`");47 testValue(0, "`0`");48 testValue(new Error(), "an error");49 testValue(new Date(), "a date");50 testValue({}, "an object");51 testValue({ then: 5 }, "an object with a non-function `then` property");52 });53 describe("3.2.6.2: If either `onFulfilled` or `onRejected` throws an exception, `promise2` " +54 "must be rejected with the thrown exception as the reason.", function () {55 function testReason(expectedReason, stringRepresentation) {56 describe("The reason is " + stringRepresentation, function () {57 testFulfilled(dummy, function (promise1, done) {58 var promise2 = promise1.then(function onFulfilled() {59 throw expectedReason;60 });61 promise2.then(null, function onPromise2Rejected(actualReason) {62 assert.strictEqual(actualReason, expectedReason);63 done();64 });65 });66 testRejected(dummy, function (promise1, done) {67 var promise2 = promise1.then(null, function onRejected() {68 throw expectedReason;69 });70 promise2.then(null, function onPromise2Rejected(actualReason) {71 assert.strictEqual(actualReason, expectedReason);72 done();73 });74 });75 });76 }77 testReason(undefined, "`undefined`");78 testReason(null, "`null`");79 testReason(false, "`false`");80 testReason(0, "`0`");81 testReason(new Error(), "an error");82 testReason(new Date(), "a date");83 testReason({}, "an object");84 testReason({ then: function () { } }, "a promise-alike");85 testReason(fulfilled(dummy), "a fulfilled promise");86 var promise = rejected(dummy); promise.caught(function(){});87 testReason(promise, "a rejected promise");88 });89 describe("3.2.6.3: If either `onFulfilled` or `onRejected` returns a promise (call it `returnedPromise`), " +90 "`promise2` must assume the state of `returnedPromise`", function () {91 describe("3.2.6.3.1: If `returnedPromise` is pending, `promise2` must remain pending until `returnedPromise` " +92 "is fulfilled or rejected.", function () {93 testFulfilled(dummy, function (promise1, done) {94 var wasFulfilled = false;95 var wasRejected = false;96 var promise2 = promise1.then(function onFulfilled() {97 var returnedPromise = pending().promise;98 return returnedPromise;99 });100 promise2.then(101 function onPromise2Fulfilled() {102 wasFulfilled = true;103 },104 function onPromise2Rejected() {105 wasRejected = true;106 }107 );108 setTimeout(function () {109 assert.strictEqual(wasFulfilled, false);110 assert.strictEqual(wasRejected, false);111 done();112 }, 100);113 });114 testRejected(dummy, function (promise1, done) {115 var wasFulfilled = false;116 var wasRejected = false;117 var promise2 = promise1.then(null, function onRejected() {118 var returnedPromise = pending().promise;119 return returnedPromise;120 });121 promise2.then(122 function onPromise2Fulfilled() {123 wasFulfilled = true;124 },125 function onPromise2Rejected() {126 wasRejected = true;127 }128 );129 setTimeout(function () {130 assert.strictEqual(wasFulfilled, false);131 assert.strictEqual(wasRejected, false);132 done();133 }, 100);134 });135 });136 describe("3.2.6.3.2: If/when `returnedPromise` is fulfilled, `promise2` must be fulfilled with the same value.",137 function () {138 describe("`promise1` is fulfilled, and `returnedPromise` is:", function () {139 testFulfilled(sentinel, function (returnedPromise, done) {140 var promise1 = fulfilled(dummy);141 var promise2 = promise1.then(function onFulfilled() {142 return returnedPromise;143 });144 promise2.then(function onPromise2Fulfilled(value) {145 assert.strictEqual(value, sentinel);146 done();147 });148 });149 specify("a pseudo-promise", function (done) {150 var promise1 = fulfilled(dummy);151 var promise2 = promise1.then(function onFulfilled() {152 return {153 then: function (f) { f(sentinel); }154 };155 });156 promise2.then(function onPromise2Fulfilled(value) {157 assert.strictEqual(value, sentinel);158 done();159 });160 });161 });162 describe("`promise1` is rejected, and `returnedPromise` is:", function () {163 testFulfilled(sentinel, function (returnedPromise, done) {164 var promise1 = rejected(dummy);165 var promise2 = promise1.then(null, function onRejected() {166 return returnedPromise;167 });168 promise2.then(function onPromise2Fulfilled(value) {169 assert.strictEqual(value, sentinel);170 done();171 });172 });173 specify("a pseudo-promise", function (done) {174 var promise1 = rejected(dummy);175 var promise2 = promise1.then(null, function onRejected() {176 return {177 then: function (f) { f(sentinel); }178 };179 });180 promise2.then(function onPromise2Fulfilled(value) {181 assert.strictEqual(value, sentinel);182 done();183 });184 });185 });186 });187 describe("3.2.6.3.3: If/when `returnedPromise` is rejected, `promise2` must be rejected with the same reason.",188 function () {189 describe("`promise1` is fulfilled, and `returnedPromise` is:", function () {190 testRejected(sentinel, function (returnedPromise, done) {191 var promise1 = fulfilled(dummy);192 var promise2 = promise1.then(function onFulfilled() {193 return returnedPromise;194 });195 promise2.then(null, function onPromise2Rejected(reason) {196 assert.strictEqual(reason, sentinel);197 done();198 });199 });200 specify("a pseudo-promise", function (done) {201 var promise1 = fulfilled(dummy);202 var promise2 = promise1.then(function onFulfilled() {203 return {204 then: function (f, r) { r(sentinel); }205 };206 });207 promise2.then(null, function onPromise2Rejected(reason) {208 assert.strictEqual(reason, sentinel);209 done();210 });211 });212 });213 describe("`promise1` is rejected, and `returnedPromise` is:", function () {214 testRejected(sentinel, function (returnedPromise, done) {215 var promise1 = rejected(dummy);216 var promise2 = promise1.then(null, function onRejected() {217 return returnedPromise;218 });219 promise2.then(null, function onPromise2Rejected(reason) {220 assert.strictEqual(reason, sentinel);221 done();222 });223 });224 specify("a pseudo-promise", function (done) {225 var promise1 = rejected(dummy);226 var promise2 = promise1.then(null, function onRejected() {227 return {228 then: function (f, r) { r(sentinel); }229 };230 });231 promise2.then(null, function onPromise2Rejected(reason) {232 assert.strictEqual(reason, sentinel);233 done();234 });235 });236 });237 });238 });239 describe("3.2.6.4: If `onFulfilled` is not a function and `promise1` is fulfilled, `promise2` must be fulfilled " +240 "with the same value.", function () {241 function testNonFunction(nonFunction, stringRepresentation) {242 describe("`onFulfilled` is " + stringRepresentation, function () {243 testFulfilled(sentinel, function (promise1, done) {244 var promise2 = promise1.then(nonFunction);245 promise2.then(function onPromise2Fulfilled(value) {246 assert.strictEqual(value, sentinel);247 done();248 });249 });250 });251 }252 testNonFunction(undefined, "`undefined`");253 testNonFunction(null, "`null`");254 testNonFunction(false, "`false`");255 testNonFunction(5, "`5`");256 testNonFunction({}, "an object");257 testNonFunction([function () { return other; }], "an array containing a function");258 });259 describe("3.2.6.5: If `onRejected` is not a function and `promise1` is rejected, `promise2` must be rejected " +260 "with the same reason.", function () {261 function testNonFunction(nonFunction, stringRepresentation) {262 describe("`onRejected` is " + stringRepresentation, function () {263 testRejected(sentinel, function (promise1, done) {264 var promise2 = promise1.then(null, nonFunction);265 promise2.then(null, function onPromise2Rejected(reason) {266 assert.strictEqual(reason, sentinel);267 done();268 });269 });270 });271 }272 testNonFunction(undefined, "`undefined`");273 testNonFunction(null, "`null`");274 testNonFunction(false, "`false`");275 testNonFunction(5, "`5`");276 testNonFunction({}, "an object");277 testNonFunction([function () { return other; }], "an array containing a function");278 });...

Full Screen

Full Screen

exercise.js

Source:exercise.js Github

copy

Full Screen

1// 1、基础题2// 题目一3// const promise1 = new Promise((resolve, reject) => {4// console.log('promise1')5// })6// console.log('1', promise1);7// 输出结果 promise1 '1' Promise{<pending>} 8// 题目二9// const promise = new Promise((resolve, reject) => {10// console.log(1);11// resolve('success') // 遇到resolve('success'), 将promise的状态改为了resolved并且将值保存下来12// console.log(2);13// });14// promise.then(() => {15// console.log(3);16// });17// console.log(4);18// 输出结果 1 2 4 3 19// 题目三20// const promise = new Promise((resolve, reject) => {21// console.log(1);22// console.log(2);23// });24// promise.then(() => {25// console.log(3);26// });27// console.log(4);28// 和题目二相似,只不过在promise中并没有resolve或者reject29// 因此promise.then并不会执行,它只有在被改变了状态之后才会执行。30// 输出结果 1 2 4 31// 题目四32// const promise1 = new Promise((resolve, reject) => {33// console.log('promise1')34// resolve('resolve1')35// })36// const promise2 = promise1.then(res => {37// console.log(res)38// })39// console.log('1', promise1);40// console.log('2', promise2);41// 输出结果 promise1 1 Promise{<resolved>: 'resolve1'} '2' Promise{<pending>} resolve142// 题目五43// const fn = () => (new Promise((resolve, reject) => {44// console.log(1);45// resolve('success')46// }))47// fn().then(res => {48// console.log(res)49// })50// console.log('start')51// 输出结果 1 start success52// 题目六53// const fn = () =>54// new Promise((resolve, reject) => {55// console.log(1);56// resolve("success");57// });58// console.log("start");59// fn().then(res => {60// console.log(res);61// });62// 输出结果 start 1 success63// 2. Promise结合setTimeout64// 题目一65// console.log('start')66// setTimeout(() => {67// console.log('time')68// })69// Promise.resolve().then(() => {70// console.log('resolve')71// })72// console.log('end')73// 输出结果 start end resolve time 74// 题目二75// const promise = new Promise((resolve, reject) => {76// console.log(1);77// setTimeout(() => {78// console.log("timerStart");79// resolve("success");80// console.log("timerEnd");81// }, 0);82// console.log(2);83// });84// promise.then((res) => {85// console.log(res);86// });87// console.log(4);88//过程分析:89// 从上至下,先遇到new Promise,执行该构造函数中的代码190// 然后碰到了定时器,将这个定时器中的函数放到下一个宏任务的延迟队列中等待执行91// 执行同步代码292// 跳出promise函数,遇到promise.then,但其状态还是为pending,这里理解为先不执行93// 执行同步代码494// 一轮循环过后,进入第二次宏任务,发现延迟队列中有setTimeout定时器,执行它95// 首先执行timerStart,然后遇到了resolve,将promise的状态改为resolved且保存结果并将之前的promise.then推入微任务队列96// 继续执行同步代码timerEnd97// 宏任务全部执行完毕,查找微任务队列,发现promise.then这个微任务,执行它。98// 输出结果 1 2 4 timerStart timerEnd success99// 题目三100// setTimeout(() => {101// console.log('timer1');102// setTimeout(() => {103// console.log('timer3')104// }, 0)105// }, 0)106// setTimeout(() => {107// console.log('timer2')108// }, 0)109// console.log('start')110// 输出结果 start timer1 timer2 timer3111// setTimeout(() => {112// console.log('timer1');113// Promise.resolve().then(() => {114// console.log('promise')115// })116// }, 0)117// setTimeout(() => {118// console.log('timer2')119// }, 0)120// console.log('start')121// 输出结果 start timer1 promise timer2122// 题目四123Promise.resolve().then(() => {124 console.log('promise1');125 const timer2 = setTimeout(() => {126 console.log('timer2')127 }, 0)128});129const timer1 = setTimeout(() => {130 console.log('timer1')131 Promise.resolve().then(() => {132 console.log('promise2')133 })134}, 0)135console.log('start');136// 输出结果 start promise1 timer1 promise2 timer2137// 题目五138// const promise1 = new Promise((resolve, reject) => {139// setTimeout(() => {140// resolve('success')141// }, 1000)142// })143// const promise2 = promise1.then(() => {144// throw new Error('error!!!')145// })146// console.log('promise1', promise1)147// console.log('promise2', promise2)148// setTimeout(() => {149// console.log('promise1', promise1)150// console.log('promise2', promise2)151// }, 2000)152// 输出结果 153// promise1 promise1<pending> 154// promise2 promise2<pending> 155// test5.html:102 Uncaught (in promise) Error: error!!! at test.html:102156//'promise1' Promise{<resolved>: "success"} 157//'promise2' Promise{<rejected>: Error: error!!!}158// 题目六159const promise1 = new Promise((resolve, reject) => {160 setTimeout(() => {161 resolve("success");162 console.log("timer1");163 }, 1000);164 console.log("promise1里的内容");165});166const promise2 = promise1.then(() => {167 throw new Error("error!!!");168});169console.log("promise1", promise1);170console.log("promise2", promise2);171setTimeout(() => {172 console.log("timer2");173 console.log("promise1", promise1);174 console.log("promise2", promise2);175}, 2000);176// promise1里的内容 177// promise1 promise1<pending> 178// promise2 promise2<pending>179// timer1180// test5.html:102 Uncaught (in promise) Error: error!!! at test.html:102181// timer2182// promise1 Promise{<resolved>: "success"}183// 'promise2' Promise{<rejected>: Error: error!!!}184// 3. Promise中的then、catch、finally185// 题目一186// 题目二187// 题目三...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('webdriverio').remote({2 desiredCapabilities: {3 }4});5 .init()6 .title(function(err, res) {7 console.log('Title was: ' + res.value);8 })9 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var promise1 = require('./promise1.js');2promise1.then(function (data) {3 console.log(data);4}).catch(function (err) {5 console.log(err);6});7var promise2 = require('./promise2.js');8promise2.then(function (data) {9 console.log(data);10}).catch(function (err) {11 console.log(err);12});13var promise3 = require('./promise3.js');14promise3.then(function (data) {15 console.log(data);16}).catch(function (err) {17 console.log(err);18});19var callback1 = require('./callback1.js');20callback1(function (data) {21 console.log(data);22});23var callback2 = require('./callback2.js');24callback2(function (data) {25 console.log(data);26});27var callback3 = require('./callback3.js');28callback3(function (data) {29 console.log(data);30});31var async1 = require('./async1.js');32async function test() {33 var data = await async1();34 console.log(data);35}36test();37var async2 = require('./async2.js');38async function test() {39 var data = await async2();40 console.log(data);41}42test();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3});4test.then(function(data) {5 console.log(data);6}, function(err) {7 console.log(err);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var util = require('util');3var fs = require('fs');4var exec = require('child_process').exec;5var request = require('request');6var url = require('url');7var path = require('path');8var http = require('http');9var https = require('https');10var url = require('url');11var path = require('path');12var http = require('http');13var https = require('https');14var url = require('url');15var path = require('path');16var http = require('http');17var https = require('https');18var url = require('url');19var path = require('path');20var http = require('http');21var https = require('https');22var url = require('url');23var path = require('path');24var http = require('http');25var https = require('https');26var url = require('url');27var path = require('path');28var http = require('http');29var https = require('https');30var url = require('url');31var path = require('path');32var http = require('http');33var https = require('https');34var url = require('url');35var path = require('path');36var http = require('http');37var https = require('https');38var url = require('url');39var path = require('path');40var http = require('http');41var https = require('https');42var url = require('url');43var path = require('path');44var http = require('http');45var https = require('https');46var url = require('url');47var path = require('path');48var http = require('http');49var https = require('https');50var url = require('url');51var path = require('path');52var wpt = new WebPageTest('www.webpagetest.org', 'A.3c1a3d1b1e7a3f8e9f7bf9b8b6e7a0a8');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var page = wptools.page('Barack Obama');4page.get(function(err, resp) {5 fs.writeFile('test.json', JSON.stringify(resp), (err) => {6 if (err) throw err;7 console.log('The file has been saved!');8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var webPageTest = new wpt('www.webpagetest.org', 'A.0f9d9f9f9f9f9f9f9f9f9f9f9f9f9f9f9');3 console.log('Test ID: ' + data.data.testId);4 console.log(data);5});6 console.log('Test ID: ' + data.data.testId);7 console.log(data);8});9 console.log('Test ID: ' + data.data.testId);10 console.log(data);11});12 console.log('Test ID: ' + data.data.testId);13 console.log(data);14});15 console.log('Test ID: ' + data.data.testId);16 console.log(data);17});18 console.log('Test ID: ' + data.data.testId);19 console.log(data);20});21 console.log('Test ID: ' + data.data.testId);22 console.log(data);23});24 console.log('Test ID: ' + data.data.testId);25 console.log(data);26});27webPageTest.runTest('http

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.3c3b9e2d3a6e7d3b4c4b4a4a4a4a4a4a');3var options = {4 lighthouseConfig: {5 settings: {6 },7 },8};9 if (err) return console.log(err);10 console.log('Test ID: %s', data.data.testId);11 wpt.getTestResults(data.data.testId, function(err, data) {12 if (err) return console.log(err);13 console.log('Speed Index: %s', data.data.average.firstView.SpeedIndex);14 });15});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var api = new wpt(options);5var location = 'Dulles_MotoG4:Chrome.56';6var runtest = new Promise(function(resolve, reject) {7 api.runTest(url, {8 }, function(err, data) {9 if (err) {10 reject(err);11 } else {12 resolve(data);13 }14 });15});16runtest.then(function(data) {17 console.log(data);18 console.log('testId: ' + data.data.testId);19 console.log('ownerKey: ' + data.data.ownerKey);20 console.log('jsonUrl: ' + data.data.jsonUrl);21 console.log('xmlUrl: ' + data.data.xmlUrl);22 console.log('userUrl: ' + data.data.userUrl);23 console.log('summaryCSV: ' + data.data.summaryCSV);24 console.log('detailCSV: ' + data.data.detailCSV);25});26runtest.catch(function(err) {27 console.log(err);28});29var wpt = require('webpagetest');30var options = {31};32var api = new wpt(options);33var location = 'Dulles_MotoG4:Chrome.56';34var runtest = new Promise(function(resolve, reject) {35 api.runTest(url, {36 }, function(err, data) {37 if (err) {38 reject(err);39 } else {40 resolve(data);41 }42 });43});44runtest.then(function(data) {45 console.log(data);46 console.log('test

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful