How to use promise.resolve method in sinon

Best JavaScript code snippet using sinon

promises.js

Source:promises.js Github

copy

Full Screen

1// Copyright 2013 the V8 project authors. All rights reserved.2// Redistribution and use in source and binary forms, with or without3// modification, are permitted provided that the following conditions are4// met:5//6// * Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// * Redistributions in binary form must reproduce the above9// copyright notice, this list of conditions and the following10// disclaimer in the documentation and/or other materials provided11// with the distribution.12// * Neither the name of Google Inc. nor the names of its13// contributors may be used to endorse or promote products derived14// from this software without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27// Flags: --harmony-promises --harmony-observation --allow-natives-syntax28var asyncAssertsExpected = 0;29function assertAsyncRan() { ++asyncAssertsExpected }30function assertAsync(b, s) {31 if (b) {32 print(s, "succeeded")33 } else {34 %AbortJS(s + " FAILED!") // Simply throwing here will have no effect.35 }36 --asyncAssertsExpected37}38function assertAsyncDone(iteration) {39 var iteration = iteration || 040 var dummy = {}41 Object.observe(dummy,42 function() {43 if (asyncAssertsExpected === 0)44 assertAsync(true, "all")45 else if (iteration > 10) // Shouldn't take more.46 assertAsync(false, "all")47 else48 assertAsyncDone(iteration + 1)49 }50 )51 dummy.dummy = dummy52}53(function() {54 assertThrows(function() { Promise(function() {}) }, TypeError)55})();56(function() {57 assertTrue(new Promise(function() {}) instanceof Promise)58})();59(function() {60 assertThrows(function() { new Promise(5) }, TypeError)61})();62(function() {63 assertDoesNotThrow(function() { new Promise(function() { throw 5 }) })64})();65(function() {66 (new Promise(function() { throw 5 })).chain(67 assertUnreachable,68 function(r) { assertAsync(r === 5, "new-throw") }69 )70 assertAsyncRan()71})();72(function() {73 Promise.resolve(5);74 Promise.resolve(5).chain(undefined, assertUnreachable).chain(75 function(x) { assertAsync(x === 5, "resolved/chain-nohandler") },76 assertUnreachable77 )78 assertAsyncRan()79})();80(function() {81 Promise.reject(5).chain(assertUnreachable, undefined).chain(82 assertUnreachable,83 function(r) { assertAsync(r === 5, "rejected/chain-nohandler") }84 )85 assertAsyncRan()86})();87(function() {88 Promise.resolve(5).then(undefined, assertUnreachable).chain(89 function(x) { assertAsync(x === 5, "resolved/then-nohandler") },90 assertUnreachable91 )92 assertAsyncRan()93})();94(function() {95 Promise.reject(5).then(assertUnreachable, undefined).chain(96 assertUnreachable,97 function(r) { assertAsync(r === 5, "rejected/then-nohandler") }98 )99 assertAsyncRan()100})();101(function() {102 var p1 = Promise.resolve(5)103 var p2 = Promise.resolve(p1)104 var p3 = Promise.resolve(p2)105 p3.chain(106 function(x) { assertAsync(x === p2, "resolved/chain") },107 assertUnreachable108 )109 assertAsyncRan()110})();111(function() {112 var p1 = Promise.resolve(5)113 var p2 = Promise.resolve(p1)114 var p3 = Promise.resolve(p2)115 p3.then(116 function(x) { assertAsync(x === 5, "resolved/then") },117 assertUnreachable118 )119 assertAsyncRan()120})();121(function() {122 var p1 = Promise.reject(5)123 var p2 = Promise.resolve(p1)124 var p3 = Promise.resolve(p2)125 p3.chain(126 function(x) { assertAsync(x === p2, "rejected/chain") },127 assertUnreachable128 )129 assertAsyncRan()130})();131(function() {132 var p1 = Promise.reject(5)133 var p2 = Promise.resolve(p1)134 var p3 = Promise.resolve(p2)135 p3.then(136 assertUnreachable,137 function(x) { assertAsync(x === 5, "rejected/then") }138 )139 assertAsyncRan()140})();141(function() {142 var p1 = Promise.resolve(5)143 var p2 = Promise.resolve(p1)144 var p3 = Promise.resolve(p2)145 p3.chain(function(x) { return x }, assertUnreachable).chain(146 function(x) { assertAsync(x === p1, "resolved/chain/chain") },147 assertUnreachable148 )149 assertAsyncRan()150})();151(function() {152 var p1 = Promise.resolve(5)153 var p2 = Promise.resolve(p1)154 var p3 = Promise.resolve(p2)155 p3.chain(function(x) { return x }, assertUnreachable).then(156 function(x) { assertAsync(x === 5, "resolved/chain/then") },157 assertUnreachable158 )159 assertAsyncRan()160})();161(function() {162 var p1 = Promise.resolve(5)163 var p2 = Promise.resolve(p1)164 var p3 = Promise.resolve(p2)165 p3.chain(function(x) { return 6 }, assertUnreachable).chain(166 function(x) { assertAsync(x === 6, "resolved/chain/chain2") },167 assertUnreachable168 )169 assertAsyncRan()170})();171(function() {172 var p1 = Promise.resolve(5)173 var p2 = Promise.resolve(p1)174 var p3 = Promise.resolve(p2)175 p3.chain(function(x) { return 6 }, assertUnreachable).then(176 function(x) { assertAsync(x === 6, "resolved/chain/then2") },177 assertUnreachable178 )179 assertAsyncRan()180})();181(function() {182 var p1 = Promise.resolve(5)183 var p2 = Promise.resolve(p1)184 var p3 = Promise.resolve(p2)185 p3.then(function(x) { return x + 1 }, assertUnreachable).chain(186 function(x) { assertAsync(x === 6, "resolved/then/chain") },187 assertUnreachable188 )189 assertAsyncRan()190})();191(function() {192 var p1 = Promise.resolve(5)193 var p2 = Promise.resolve(p1)194 var p3 = Promise.resolve(p2)195 p3.then(function(x) { return x + 1 }, assertUnreachable).then(196 function(x) { assertAsync(x === 6, "resolved/then/then") },197 assertUnreachable198 )199 assertAsyncRan()200})();201(function() {202 var p1 = Promise.resolve(5)203 var p2 = Promise.resolve(p1)204 var p3 = Promise.resolve(p2)205 p3.then(function(x){ return Promise.resolve(x+1) }, assertUnreachable).chain(206 function(x) { assertAsync(x === 6, "resolved/then/chain2") },207 assertUnreachable208 )209 assertAsyncRan()210})();211(function() {212 var p1 = Promise.resolve(5)213 var p2 = Promise.resolve(p1)214 var p3 = Promise.resolve(p2)215 p3.then(function(x) { return Promise.resolve(x+1) }, assertUnreachable).then(216 function(x) { assertAsync(x === 6, "resolved/then/then2") },217 assertUnreachable218 )219 assertAsyncRan()220})();221(function() {222 var p1 = Promise.resolve(5)223 var p2 = Promise.resolve(p1)224 var p3 = Promise.resolve(p2)225 p3.chain(function(x) { throw 6 }, assertUnreachable).chain(226 assertUnreachable,227 function(x) { assertAsync(x === 6, "resolved/chain-throw/chain") }228 )229 assertAsyncRan()230})();231(function() {232 var p1 = Promise.resolve(5)233 var p2 = Promise.resolve(p1)234 var p3 = Promise.resolve(p2)235 p3.chain(function(x) { throw 6 }, assertUnreachable).then(236 assertUnreachable,237 function(x) { assertAsync(x === 6, "resolved/chain-throw/then") }238 )239 assertAsyncRan()240})();241(function() {242 var p1 = Promise.resolve(5)243 var p2 = Promise.resolve(p1)244 var p3 = Promise.resolve(p2)245 p3.then(function(x) { throw 6 }, assertUnreachable).chain(246 assertUnreachable,247 function(x) { assertAsync(x === 6, "resolved/then-throw/chain") }248 )249 assertAsyncRan()250})();251(function() {252 var p1 = Promise.resolve(5)253 var p2 = Promise.resolve(p1)254 var p3 = Promise.resolve(p2)255 p3.then(function(x) { throw 6 }, assertUnreachable).then(256 assertUnreachable,257 function(x) { assertAsync(x === 6, "resolved/then-throw/then") }258 )259 assertAsyncRan()260})();261(function() {262 var p1 = Promise.resolve(5)263 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}264 var p3 = Promise.resolve(p2)265 p3.chain(266 function(x) { assertAsync(x === p2, "resolved/thenable/chain") },267 assertUnreachable268 )269 assertAsyncRan()270})();271(function() {272 var p1 = Promise.resolve(5)273 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}274 var p3 = Promise.resolve(p2)275 p3.then(276 function(x) { assertAsync(x === 5, "resolved/thenable/then") },277 assertUnreachable278 )279 assertAsyncRan()280})();281(function() {282 var p1 = Promise.reject(5)283 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}284 var p3 = Promise.resolve(p2)285 p3.chain(286 function(x) { assertAsync(x === p2, "rejected/thenable/chain") },287 assertUnreachable288 )289 assertAsyncRan()290})();291(function() {292 var p1 = Promise.reject(5)293 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}294 var p3 = Promise.resolve(p2)295 p3.then(296 assertUnreachable,297 function(x) { assertAsync(x === 5, "rejected/thenable/then") }298 )299 assertAsyncRan()300})();301(function() {302 var deferred = Promise.defer()303 var p1 = deferred.promise304 var p2 = Promise.resolve(p1)305 var p3 = Promise.resolve(p2)306 p3.chain(307 function(x) { assertAsync(x === p2, "chain/resolve") },308 assertUnreachable309 )310 deferred.resolve(5)311 assertAsyncRan()312})();313(function() {314 var deferred = Promise.defer()315 var p1 = deferred.promise316 var p2 = Promise.resolve(p1)317 var p3 = Promise.resolve(p2)318 p3.then(319 function(x) { assertAsync(x === 5, "then/resolve") },320 assertUnreachable321 )322 deferred.resolve(5)323 assertAsyncRan()324})();325(function() {326 var deferred = Promise.defer()327 var p1 = deferred.promise328 var p2 = Promise.resolve(p1)329 var p3 = Promise.resolve(p2)330 p3.chain(331 function(x) { assertAsync(x === p2, "chain/reject") },332 assertUnreachable333 )334 deferred.reject(5)335 assertAsyncRan()336})();337(function() {338 var deferred = Promise.defer()339 var p1 = deferred.promise340 var p2 = Promise.resolve(p1)341 var p3 = Promise.resolve(p2)342 p3.then(343 assertUnreachable,344 function(x) { assertAsync(x === 5, "then/reject") }345 )346 deferred.reject(5)347 assertAsyncRan()348})();349(function() {350 var deferred = Promise.defer()351 var p1 = deferred.promise352 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}353 var p3 = Promise.resolve(p2)354 p3.chain(355 function(x) { assertAsync(x === p2, "chain/resolve/thenable") },356 assertUnreachable357 )358 deferred.resolve(5)359 assertAsyncRan()360})();361(function() {362 var deferred = Promise.defer()363 var p1 = deferred.promise364 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}365 var p3 = Promise.resolve(p2)366 p3.then(367 function(x) { assertAsync(x === 5, "then/resolve/thenable") },368 assertUnreachable369 )370 deferred.resolve(5)371 assertAsyncRan()372})();373(function() {374 var deferred = Promise.defer()375 var p1 = deferred.promise376 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}377 var p3 = Promise.resolve(p2)378 p3.chain(379 function(x) { assertAsync(x === p2, "chain/reject/thenable") },380 assertUnreachable381 )382 deferred.reject(5)383 assertAsyncRan()384})();385(function() {386 var deferred = Promise.defer()387 var p1 = deferred.promise388 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}389 var p3 = Promise.resolve(p2)390 p3.then(391 assertUnreachable,392 function(x) { assertAsync(x === 5, "then/reject/thenable") }393 )394 deferred.reject(5)395 assertAsyncRan()396})();397(function() {398 var p1 = Promise.resolve(5)399 var p2 = Promise.resolve(p1)400 var deferred = Promise.defer()401 var p3 = deferred.promise402 p3.chain(403 function(x) { assertAsync(x === p2, "chain/resolve2") },404 assertUnreachable405 )406 deferred.resolve(p2)407 assertAsyncRan()408})();409(function() {410 var p1 = Promise.resolve(5)411 var p2 = Promise.resolve(p1)412 var deferred = Promise.defer()413 var p3 = deferred.promise414 p3.then(415 function(x) { assertAsync(x === 5, "then/resolve2") },416 assertUnreachable417 )418 deferred.resolve(p2)419 assertAsyncRan()420})();421(function() {422 var p1 = Promise.resolve(5)423 var p2 = Promise.resolve(p1)424 var deferred = Promise.defer()425 var p3 = deferred.promise426 p3.chain(427 assertUnreachable,428 function(x) { assertAsync(x === 5, "chain/reject2") }429 )430 deferred.reject(5)431 assertAsyncRan()432})();433(function() {434 var p1 = Promise.resolve(5)435 var p2 = Promise.resolve(p1)436 var deferred = Promise.defer()437 var p3 = deferred.promise438 p3.then(439 assertUnreachable,440 function(x) { assertAsync(x === 5, "then/reject2") }441 )442 deferred.reject(5)443 assertAsyncRan()444})();445(function() {446 var p1 = Promise.resolve(5)447 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}448 var deferred = Promise.defer()449 var p3 = deferred.promise450 p3.chain(451 function(x) { assertAsync(x === p2, "chain/resolve/thenable2") },452 assertUnreachable453 )454 deferred.resolve(p2)455 assertAsyncRan()456})();457(function() {458 var p1 = Promise.resolve(5)459 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}460 var deferred = Promise.defer()461 var p3 = deferred.promise462 p3.then(463 function(x) { assertAsync(x === 5, "then/resolve/thenable2") },464 assertUnreachable465 )466 deferred.resolve(p2)467 assertAsyncRan()468})();469(function() {470 var p1 = Promise.resolve(0)471 var p2 = p1.chain(function(x) { return p2 }, assertUnreachable)472 p2.chain(473 assertUnreachable,474 function(r) { assertAsync(r instanceof TypeError, "cyclic/chain") }475 )476 assertAsyncRan()477})();478(function() {479 var p1 = Promise.resolve(0)480 var p2 = p1.then(function(x) { return p2 }, assertUnreachable)481 p2.chain(482 assertUnreachable,483 function(r) { assertAsync(r instanceof TypeError, "cyclic/then") }484 )485 assertAsyncRan()486})();487(function() {488 var deferred = Promise.defer()489 var p = deferred.promise490 deferred.resolve(p)491 p.chain(492 function(x) { assertAsync(x === p, "cyclic/deferred/chain") },493 assertUnreachable494 )495 assertAsyncRan()496})();497(function() {498 var deferred = Promise.defer()499 var p = deferred.promise500 deferred.resolve(p)501 p.then(502 assertUnreachable,503 function(r) { assertAsync(r instanceof TypeError, "cyclic/deferred/then") }504 )505 assertAsyncRan()506})();507(function() {508 Promise.all({get length() { throw 666 }}).chain(509 assertUnreachable,510 function(r) { assertAsync(r === 666, "all/no-array") }511 )512 assertAsyncRan()513})();514(function() {515 Promise.all([]).chain(516 function(x) { assertAsync(x.length === 0, "all/resolve/empty") },517 assertUnreachable518 )519 assertAsyncRan()520})();521(function() {522 var deferred1 = Promise.defer()523 var p1 = deferred1.promise524 var deferred2 = Promise.defer()525 var p2 = deferred2.promise526 var deferred3 = Promise.defer()527 var p3 = deferred3.promise528 Promise.all([p1, p2, p3]).chain(529 function(x) {530 assertAsync(x.length === 3, "all/resolve")531 assertAsync(x[0] === 1, "all/resolve/0")532 assertAsync(x[1] === 2, "all/resolve/1")533 assertAsync(x[2] === 3, "all/resolve/2")534 },535 assertUnreachable536 )537 deferred1.resolve(1)538 deferred3.resolve(3)539 deferred2.resolve(2)540 assertAsyncRan()541 assertAsyncRan()542 assertAsyncRan()543 assertAsyncRan()544})();545(function() {546 var deferred = Promise.defer()547 var p1 = deferred.promise548 var p2 = Promise.resolve(2)549 var p3 = Promise.defer().promise550 Promise.all([p1, p2, p3]).chain(551 assertUnreachable,552 assertUnreachable553 )554 deferred.resolve(1)555})();556(function() {557 var deferred1 = Promise.defer()558 var p1 = deferred1.promise559 var deferred2 = Promise.defer()560 var p2 = deferred2.promise561 var deferred3 = Promise.defer()562 var p3 = deferred3.promise563 Promise.all([p1, p2, p3]).chain(564 assertUnreachable,565 function(x) { assertAsync(x === 2, "all/reject") }566 )567 deferred1.resolve(1)568 deferred3.resolve(3)569 deferred2.reject(2)570 assertAsyncRan()571})();572(function() {573 Promise.race([]).chain(574 assertUnreachable,575 assertUnreachable576 )577})();578(function() {579 var p1 = Promise.resolve(1)580 var p2 = Promise.resolve(2)581 var p3 = Promise.resolve(3)582 Promise.race([p1, p2, p3]).chain(583 function(x) { assertAsync(x === 1, "resolved/one") },584 assertUnreachable585 )586 assertAsyncRan()587})();588(function() {589 var p1 = Promise.resolve(1)590 var p2 = Promise.resolve(2)591 var p3 = Promise.resolve(3)592 Promise.race([0, p1, p2, p3]).chain(593 function(x) { assertAsync(x === 0, "resolved-const/one") },594 assertUnreachable595 )596 assertAsyncRan()597})();598(function() {599 Promise.race({get length() { throw 666 }}).chain(600 assertUnreachable,601 function(r) { assertAsync(r === 666, "one/no-array") }602 )603 assertAsyncRan()604})();605(function() {606 var deferred1 = Promise.defer()607 var p1 = deferred1.promise608 var deferred2 = Promise.defer()609 var p2 = deferred2.promise610 var deferred3 = Promise.defer()611 var p3 = deferred3.promise612 Promise.race([p1, p2, p3]).chain(613 function(x) { assertAsync(x === 3, "one/resolve") },614 assertUnreachable615 )616 deferred3.resolve(3)617 deferred1.resolve(1)618 assertAsyncRan()619})();620(function() {621 var deferred = Promise.defer()622 var p1 = deferred.promise623 var p2 = Promise.resolve(2)624 var p3 = Promise.defer().promise625 Promise.race([p1, p2, p3]).chain(626 function(x) { assertAsync(x === 2, "resolved/one") },627 assertUnreachable628 )629 deferred.resolve(1)630 assertAsyncRan()631})();632(function() {633 var deferred1 = Promise.defer()634 var p1 = deferred1.promise635 var deferred2 = Promise.defer()636 var p2 = deferred2.promise637 var deferred3 = Promise.defer()638 var p3 = deferred3.promise639 Promise.race([p1, p2, p3]).chain(640 function(x) { assertAsync(x === 3, "one/resolve/reject") },641 assertUnreachable642 )643 deferred3.resolve(3)644 deferred1.reject(1)645 assertAsyncRan()646})();647(function() {648 var deferred1 = Promise.defer()649 var p1 = deferred1.promise650 var deferred2 = Promise.defer()651 var p2 = deferred2.promise652 var deferred3 = Promise.defer()653 var p3 = deferred3.promise654 Promise.race([p1, p2, p3]).chain(655 assertUnreachable,656 function(x) { assertAsync(x === 3, "one/reject/resolve") }657 )658 deferred3.reject(3)659 deferred1.resolve(1)660 assertAsyncRan()661})();662(function() {663 var log664 function MyPromise(resolver) {665 log += "n"666 var promise = new Promise(function(resolve, reject) {667 resolver(668 function(x) { log += "x" + x; resolve(x) },669 function(r) { log += "r" + r; reject(r) }670 )671 })672 promise.__proto__ = MyPromise.prototype673 return promise674 }675 MyPromise.__proto__ = Promise676 MyPromise.defer = function() {677 log += "d"678 return this.__proto__.defer.call(this)679 }680 MyPromise.prototype.__proto__ = Promise.prototype681 MyPromise.prototype.chain = function(resolve, reject) {682 log += "c"683 return this.__proto__.__proto__.chain.call(this, resolve, reject)684 }685 log = ""686 var p1 = new MyPromise(function(resolve, reject) { resolve(1) })687 var p2 = new MyPromise(function(resolve, reject) { reject(2) })688 var d3 = MyPromise.defer()689 assertTrue(d3.promise instanceof Promise, "subclass/instance")690 assertTrue(d3.promise instanceof MyPromise, "subclass/instance-my3")691 assertTrue(log === "nx1nr2dn", "subclass/create")692 log = ""693 var p4 = MyPromise.resolve(4)694 var p5 = MyPromise.reject(5)695 assertTrue(p4 instanceof Promise, "subclass/instance4")696 assertTrue(p4 instanceof MyPromise, "subclass/instance-my4")697 assertTrue(p5 instanceof Promise, "subclass/instance5")698 assertTrue(p5 instanceof MyPromise, "subclass/instance-my5")699 d3.resolve(3)700 assertTrue(log === "nx4nr5x3", "subclass/resolve")701 log = ""702 var d6 = MyPromise.defer()703 d6.promise.chain(function(x) {704 return new Promise(function(resolve) { resolve(x) })705 }).chain(function() {})706 d6.resolve(6)707 assertTrue(log === "dncncnx6", "subclass/chain")708 log = ""709 Promise.all([11, Promise.resolve(12), 13, MyPromise.resolve(14), 15, 16])710 assertTrue(log === "nx14cn", "subclass/all/arg")711 log = ""712 MyPromise.all([21, Promise.resolve(22), 23, MyPromise.resolve(24), 25, 26])713 assertTrue(log === "nx24nnx21cnnx23cncnnx25cnnx26cn", "subclass/all/self")714})();...

Full Screen

Full Screen

long_stack_traces.js

Source:long_stack_traces.js Github

copy

Full Screen

1var assert = require("assert");2var testUtils = require("./helpers/util.js");3var assertLongTrace = require("./helpers/assert_long_trace.js");4var nodeVersion = typeof process !== "undefined" &&5 typeof process.version === "string"6 ? process.version.replace(/[^0-9.]/g, "").split(".").map(Number)7 : [-1, -1, -1];8// Node's V8 captureStackTrace is completely broken - it returns different9// results on different runs and sometimes causes this test to fail10if (!Promise.hasLongStackTraces() || testUtils.isOldNode) return;11describe(".then as context", function() {12 it("1 level", function() {13 return Promise.resolve().then(function() {14 throw new Error();15 }).then(assert.fail, function(e) {16 assertLongTrace(e, 1 + 1, [1]);17 });18 });19 it("4 levels", function() {20 return Promise.resolve().then(function() {21 return Promise.resolve().then(function() {22 return Promise.resolve().then(function() {23 return Promise.resolve().then(function() {24 throw new Error();25 });26 });27 });28 }).then(assert.fail, function(e) {29 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);30 });31 });32 it("1 level using promise reject with no stack", function() {33 return Promise.resolve().then(function() {34 var e;35 try {throw new Error()} catch (err){e = err;}36 e.stack;37 delete e.stack;38 return Promise.reject(e);39 }).then(assert.fail, function(e) {40 assertLongTrace(e, 1 + 1, [1, 1]);41 });42 });43 it("4 levels using promise reject", function() {44 return Promise.resolve().then(function() {45 return Promise.resolve().then(function() {46 return Promise.resolve().then(function() {47 return Promise.resolve().then(function() {48 var e;49 try {throw new Error()} catch (err){e = err;}50 return Promise.reject(e);51 });52 });53 });54 }).then(assert.fail, function(e) {55 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);56 });57 });58 it("Circular 1 level", function() {59 var i = 0;60 return (function circle() {61 if (i++ > 5) throw new Error()62 return Promise.resolve().then(circle);63 })().then(assert.fail, function(e) {64 assertLongTrace(e, 1 + 1, [1]);65 });66 });67 it("Circular 4 levels", function() {68 var i = 0;69 return (function circle() {70 if (i++ > 5) throw new Error()71 return Promise.resolve().then(function() {72 return Promise.resolve().then(function() {73 return Promise.resolve().then(function() {74 return Promise.resolve().then(circle);75 });76 });77 });78 })().then(assert.fail, function(e) {79 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);80 });81 });82 it("followers unaffected", function() {83 return Promise.resolve().then(function() {84 return new Promise(function(res) {85 res(Promise.delay(13).then(function() {86 return new Promise(function(res) {87 res(Promise.delay(13).then(function() {88 throw new Error();89 }));90 });91 }));92 }).then(assert.fail, function(e) {93 assertLongTrace(e, 5 + 1, [1, 1, 1, 1, 1]);94 throw new Error();95 });96 }).then(assert.fail, function(e) {97 assertLongTrace(e, 2 + 1, [1, 1]);98 });99 });100 it("3 distinct episodes of circularity with unique frames in between", function() {101 var i = 0;102 var j = 0;103 var k = 0;104 function circle1() {105 if (i++ > 5) return u1_1();106 return Promise.resolve().then(function() {107 return Promise.resolve().then(function() {108 return Promise.resolve().then(function() {109 return Promise.resolve().then(circle1);110 });111 });112 });113 }114 function circle2() {115 if (j++ > 5) return u2_1();116 return Promise.resolve().then(function() {117 return Promise.resolve().then(function() {118 return Promise.resolve().then(function() {119 return Promise.resolve().then(circle2);120 });121 });122 });123 }124 function circle3() {125 if (k++ > 5) return u3_1();126 return Promise.resolve().then(function() {127 return Promise.resolve().then(function() {128 return Promise.resolve().then(function() {129 return Promise.resolve().then(circle3);130 });131 });132 });133 }134 function u1_1() {135 return Promise.resolve().then(u1_2);136 }137 function u1_2() {138 return Promise.resolve().then(circle2);139 }140 function u2_1() {141 return Promise.resolve().then(u2_2);142 }143 function u2_2() {144 return Promise.resolve().then(circle3);145 }146 function u3_1() {147 return Promise.resolve().then(u3_2);148 }149 function u3_2() {150 return Promise.resolve().then(function() {151 throw new Error("The error");152 });153 }154 return circle1().then(assert.fail, function(e) {155 assertLongTrace(e,156 1 + 1 + 1 + 1,157 [158 1, 1, 2, 1, 1,159 1, 1, 2, 1, 1,160 1, 1, 2, 1, 1161 ]);162 });163 });164});165describe(".spread as context", function() {166 it("1 level", function() {167 return Promise.resolve([]).spread(function() {168 throw new Error();169 }).then(assert.fail, function(e) {170 assertLongTrace(e, 1 + 1, [1]);171 });172 });173 it("4 levels", function() {174 return Promise.resolve([]).spread(function() {175 return Promise.resolve([]).spread(function() {176 return Promise.resolve([]).spread(function() {177 return Promise.resolve([]).spread(function() {178 throw new Error();179 });180 });181 });182 }).then(assert.fail, function(e) {183 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);184 });185 });186});187describe("constructor as context", function() {188 it("0 level", function() {189 return new Promise(function() {190 throw new Error();191 }).then(assert.fail, function(e) {192 assertLongTrace(e, 1, []);193 });194 });195 it("1 level", function() {196 return new Promise(function(res) {197 res(new Promise(function() {198 throw new Error();199 }))200 }).then(assert.fail, function(e) {201 assertLongTrace(e, 1 + 1, [2]);202 });203 });204 it("0 level, no stack property", function() {205 return new Promise(function(_ ,rej) {206 var e = new Error();207 e.stack;208 delete e.stack;209 rej(e);210 }).then(assert.fail, function(e) {211 assertLongTrace(e, 1, [1]);212 });213 });214 it("1 level, no stack property", function() {215 return new Promise(function(res) {216 res(new Promise(function(_, rej) {217 var e = new Error();218 e.stack;219 delete e.stack;220 rej(e);221 }))222 }).then(assert.fail, function(e) {223 assertLongTrace(e, 1 + 1, [1, 1]);224 });225 });226 it("4 levels", function() {227 return new Promise(function(res) {228 res(new Promise(function(res) {229 res(new Promise(function(res) {230 res(new Promise(function(res) {231 res(new Promise(function(res) {232 throw new Error();233 }));234 }));235 }));236 }));237 }).then(assert.fail, function(e) {238 assertLongTrace(e, 4 + 1, [2, 1, 1, 1]);239 });240 });241});242describe(".join as context", function() {243 it("0 level", function() {244 var err;245 try {throw new Error(); } catch(e) {err = e;};246 return Promise.join(1, 2, Promise.reject(err), function() {247 throw new Error();248 }).then(assert.fail, function(e) {249 assertLongTrace(e, 0 + 1, []);250 });251 });252 it("1 level", function() {253 return Promise.join(1, 2, 3, function() {254 throw new Error();255 }).then(assert.fail, function(e) {256 assertLongTrace(e, 1 + 1, [1]);257 });258 });259 it("4 levels", function() {260 return Promise.join(1, 2, 3, function() {261 return Promise.join(1, 2, 3, function() {262 return Promise.join(1, 2, 3, function() {263 return Promise.join(1, 2, 3, function() {264 throw new Error();265 });266 });267 });268 }).then(assert.fail, function(e) {269 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);270 });271 });272});273describe(".map as context", function() {274 it("1 level", function() {275 return Promise.map([1,2,3], function() {276 throw new Error();277 }).then(assert.fail, function(e) {278 assertLongTrace(e, 1 + 1, [1]);279 });280 });281 it("4 levels", function() {282 return Promise.map([1,2,3], function() {283 return Promise.map([1,2,3], function() {284 return Promise.map([1,2,3], function() {285 return Promise.map([1,2,3], function() {286 throw new Error();287 });288 });289 });290 }).then(assert.fail, function(e) {291 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);292 });293 });294});295describe(".reduce as context", function() {296 it("1 level", function() {297 return Promise.reduce([1,2,3], function() {298 throw new Error();299 }).then(assert.fail, function(e) {300 assertLongTrace(e, 1 + 1, [1]);301 });302 });303 it("4 levels", function() {304 return Promise.reduce([1,2,3], function() {305 return Promise.reduce([1,2,3], function() {306 return Promise.reduce([1,2,3], function() {307 return Promise.reduce([1,2,3], function() {308 throw new Error();309 });310 });311 });312 }).then(assert.fail, function(e) {313 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);314 });315 });316});317describe(".method as context", function() {318 it("1 level", function() {319 return Promise.method(function() {320 throw new Error();321 })().then(assert.fail, function(e) {322 assertLongTrace(e, 1 + 1, [1]);323 });324 });325 it("4 levels", function() {326 var second = Promise.method(function() {327 return third();328 });329 var third = Promise.method(function() {330 return fourth();331 });332 var fourth = Promise.method(function() {333 throw new Error();334 });335 return Promise.method(function() {336 return second();337 })().then(assert.fail, function(e) {338 assertLongTrace(e, 4 + 1, [[1,2], 1, 1, 1]);339 });340 });341});342describe(".try as context", function() {343 it("1 level", function() {344 return Promise.attempt(function() {345 throw new Error();346 }).then(assert.fail, function(e) {347 assertLongTrace(e, 1 + 1, [1]);348 });349 });350 it("4 levels", function() {351 return Promise.attempt(function() {352 return Promise.attempt(function() {353 return Promise.attempt(function() {354 return Promise.attempt(function() {355 throw new Error();356 });357 });358 });359 }).then(assert.fail, function(e) {360 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);361 });362 });363});364describe(".using as context", function() {365 it("0 level", function() {366 var err;367 try {throw new Error(); } catch(e) {err = e};368 return Promise.using(1, 2, Promise.reject(err), function() {369 throw new Error();370 }).then(assert.fail, function(e) {371 assertLongTrace(e, 0 + 1, []);372 });373 });374 it("1 level", function() {375 return Promise.using(1, 2, 3, function() {376 throw new Error();377 }).then(assert.fail, function(e) {378 assertLongTrace(e, 1 + 1, [1]);379 });380 });381 it("4 levels", function() {382 return Promise.using(1, 2, 3, function() {383 return Promise.using(1, 2, 3, function() {384 return Promise.using(1, 2, 3, function() {385 return Promise.using(1, 2, 3, function() {386 throw new Error();387 });388 });389 });390 }).then(assert.fail, function(e) {391 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);392 });393 });394});395describe("Long stack traces from thenable rejections", function() {396 var es5 = (function(){"use strict"; return this})() === undefined;397 // Todo, for 100% coverage thenables should be tested with every398 // feature, not just then399 var syncRej = function() {400 return {401 then: function(_, rej) {402 rej(new Error());403 }404 };405 };406 var asyncRej = function() {407 return {408 then: function(_, rej) {409 setTimeout(function() {410 rej(new Error());411 }, 1);412 }413 };414 };415 var throwRej = function() {416 return {417 then: function(_, rej) {418 throw(new Error());419 }420 };421 };422 var thenGetRej = function() {423 var ret = {};424 Object.defineProperty(ret, "then", {425 get: function() {426 throw new Error()427 }428 });429 return ret;430 };431 it("1 level sync reject", function() {432 return Promise.resolve().then(function() {433 return syncRej();434 }).then(assert.fail, function(e) {435 assertLongTrace(e, 1+1, [1]);436 });437 });438 it("4 levels sync reject", function() {439 return Promise.resolve().then(function() {440 return Promise.resolve().then(function() {441 return Promise.resolve().then(function() {442 return Promise.resolve().then(function() {443 return syncRej();444 });445 });446 });447 }).then(assert.fail, function(e) {448 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);449 });450 });451 it("1 level async reject", function() {452 return Promise.resolve().then(function() {453 return asyncRej();454 }).then(assert.fail, function(e) {455 assertLongTrace(e, 1 + 1, [1]);456 });457 });458 it("4 levels async reject", function() {459 return Promise.resolve().then(function() {460 return Promise.resolve().then(function() {461 return Promise.resolve().then(function() {462 return Promise.resolve().then(function() {463 return asyncRej();464 });465 });466 });467 }).then(assert.fail, function(e) {468 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);469 });470 });471 it("1 level throw", function() {472 return Promise.resolve().then(function() {473 return throwRej();474 }).then(assert.fail, function(e) {475 assertLongTrace(e, 1 + 1, [1]);476 });477 });478 it("4 levels throw", function() {479 return Promise.resolve().then(function() {480 return Promise.resolve().then(function() {481 return Promise.resolve().then(function() {482 return Promise.resolve().then(function() {483 return throwRej();484 });485 });486 });487 }).then(assert.fail, function(e) {488 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);489 });490 });491 it("1 level getter throw", function() {492 return Promise.resolve().then(function() {493 return thenGetRej();494 }).then(assert.fail, function(e) {495 assertLongTrace(e, 1 + 1, [1]);496 });497 });498 it("4 levels getter throw", function() {499 return Promise.resolve().then(function() {500 return Promise.resolve().then(function() {501 return Promise.resolve().then(function() {502 return Promise.resolve().then(function() {503 return thenGetRej();504 });505 });506 });507 }).then(assert.fail, function(e) {508 assertLongTrace(e, 4 + 1, [1, 1, 1, 1]);509 });510 });...

Full Screen

Full Screen

siteList.js

Source:siteList.js Github

copy

Full Screen

1'use strict';2var siteList = {3 ourstep: {4 url: 'http://www.oursteps.com.au/bbs/home.php?mod=space&do=thread&view=me',5 init: 'link',6 ctrl: function (adId, siteId) {7 var ad = adList[adId];8 var config = ad.sites[siteId];9 this.link = () => {10 return new Promise(11 (resolve) => {12 if ($('a:contains("' + ad.title + '")').length > 0) {13 resolve('edit');14 $('a:contains("' + ad.title + '")').removeAttr('target')[0].click();15 } else {16 resolve('clickNew');17 window.location.href = 'http://www.oursteps.com.au/bbs/forum.php?mod=forumdisplay&fid=' + config.fid;18 }19 });20 };21 this.edit = () => {22 return new Promise(23 (resolve) => {24 resolve('delete');25 $('a:contains("编辑")')[0].click();26 });27 };28 this.delete = () => {29 return new Promise(30 (resolve) => {31 resolve('afterDelete');32 $('#delete').attr('value', '1');33 $('#postform').submit();34 });35 };36 this.afterDelete = () => {37 return new Promise(38 (resolve) => {39 resolve('clickNew');40 });41 };42 this.clickNew = () => {43 return new Promise(44 (resolve) => {45 $('#newspecial')[0].click();46 resolve('enterNew');47 });48 };49 this.enterNew = () => {50 return new Promise(51 (resolve) => {52 $('#subject').val(ad.title);53 $('#typeid_ctrl')[0].click();54 $('#typeid_ctrl_menu>ul>li:contains("' + config.select + '")')[0].click();55 $('#e_textarea').val(ad.content);56 $('#e_image')[0].click();57 resolve('end');58 });59 };60 this.end = () => {61 return new Promise(62 (resolve) => {63 resolve();64 });65 };66 }67 },68 ourstepUp: {69 url: 'http://www.oursteps.com.au/bbs/home.php?mod=space&do=thread&view=me',70 init: 'link',71 ctrl: function (adId, siteId) {72 var ad = adList[adId];73 var config = ad.sites[siteId];74 this.link = () => {75 return new Promise(76 (resolve) => {77 if ($('a:contains("' + ad.title + '")').length > 0) {78 resolve('up');79 $('a:contains("' + ad.title + '")').removeAttr('target')[0].click();80 } else {81 resolve('clickNew');82 window.location.href = 'http://www.oursteps.com.au/bbs/forum.php?mod=forumdisplay&fid=' + config.fid;83 }84 });85 };86 this.up = () => {87 return new Promise(88 (resolve) => {89 resolve('close');90 $('#fastpostmessage').val('顶顶顶顶顶顶顶顶');91 $('#fastpostsubmit')[0].click();92 window.location.href = 'http://www.oursteps.com.au/bbs/forum.php?mod=forumdisplay&fid=' + config.fid;93 });94 };95 this.clickNew = () => {96 return new Promise(97 (resolve) => {98 $('#newspecial')[0].click();99 resolve('enterNew');100 });101 };102 this.enterNew = () => {103 return new Promise(104 (resolve) => {105 $('#subject').val(ad.title);106 $('#typeid_ctrl')[0].click();107 $('#typeid_ctrl_menu>ul>li:contains("' + config.select + '")')[0].click();108 $('#e_textarea').val(ad.content);109 $('#e_image')[0].click();110 resolve('end');111 });112 };113 this.end = () => {114 return new Promise(115 (resolve) => {116 resolve(false);117 });118 };119 this.close = () => {120 return new Promise(121 (resolve) => {122 resolve(true);123 });124 };125 }126 },127 freeoz: {128 url: 'http://www.freeoz.org/ibbs/forum.php?mod=guide&view=my',129 init: 'link',130 ctrl: function (adId, siteId) {131 var ad = adList[adId];132 var config = ad.sites[siteId];133 this.link = () => {134 return new Promise(135 (resolve) => {136 if ($('a:contains("' + ad.title + '")').length > 0) {137 resolve('edit');138 $('a:contains("' + ad.title + '")').removeAttr('target')[0].click();139 } else {140 resolve('clickNew');141 window.location.href = 'http://www.freeoz.org/ibbs/forum.php?mod=guide&view=my';142 }143 });144 };145 this.edit = () => {146 return new Promise(147 (resolve) => {148 resolve('delete');149 $('a:contains("编辑")')[0].click();150 });151 };152 this.delete = () => {153 return new Promise(154 (resolve) => {155 $('#extra_additional_b')[0].click();156 resolve('afterDelete');157 $('#delete').attr('value', '1');158 $('#postform').submit();159 });160 };161 this.afterDelete = () => {162 return new Promise(163 (resolve) => {164 resolve('clickNew');165 });166 };167 this.clickNew = () => {168 return new Promise(169 (resolve) => {170 resolve('enterNew');171 window.location.href = 'http://www.freeoz.org/ibbs/forum.php?mod=post&action=newthread&fid=' + config.fid;172 });173 };174 this.enterNew = () => {175 return new Promise(176 (resolve) => {177 setTimeout(()=>{178 $('#subject').val(ad.title);179 $('#e_textarea').val(ad.content);180 $('#e_image')[0].click();181 resolve('end');182 },2000);183 });184 };185 this.end = () => {186 return new Promise(187 (resolve) => {188 resolve();189 });190 };191 }192 },193 freeozUp: {194 url: 'http://www.freeoz.org/ibbs/forum.php?mod=guide&view=my',195 init: 'link',196 ctrl: function (adId, siteId) {197 var ad = adList[adId];198 var config = ad.sites[siteId];199 this.link = () => {200 return new Promise(201 (resolve) => {202 if ($('a:contains("' + ad.title + '")').length > 0) {203 resolve('up');204 $('a:contains("' + ad.title + '")').removeAttr('target')[0].click();205 } else {206 resolve('clickNew');207 window.location.href = 'http://www.freeoz.org/ibbs/forum.php?mod=guide&view=my';208 }209 });210 };211 this.up = () => {212 return new Promise(213 (resolve) => {214 resolve('close');215 $('#fastpostmessage').val('顶顶顶顶顶顶顶顶');216 $('#fastpostsubmit')[0].click();217 window.location.href = 'http://www.freeoz.org/ibbs/forum.php?mod=guide&view=my';218 });219 };220 this.clickNew = () => {221 return new Promise(222 (resolve) => {223 resolve('enterNew');224 window.location.href = 'http://www.freeoz.org/ibbs/forum.php?mod=post&action=newthread&fid=' + config.fid;225 });226 };227 this.enterNew = () => {228 return new Promise(229 (resolve) => {230 $('#subject').val(ad.title);231 $('#typeid_ctrl')[0].click();232 $('#typeid_ctrl_menu>ul>li:contains("' + ad.select + '")')[0].click();233 $('#e_textarea').val(ad.content);234 $('#e_image')[0].click();235 resolve('end');236 });237 };238 this.end = () => {239 return new Promise(240 (resolve) => {241 resolve(false);242 });243 };244 this.close = () => {245 return new Promise(246 (resolve) => {247 resolve(true);248 });249 };250 }251 },252 dida: {253 url: 'http://bbs.tigtag.com/forum.php?mod=guide&view=my',254 init: 'link',255 ctrl: function (adId, siteId) {256 var ad = adList[adId];257 var config = ad.sites[siteId];258 this.link = () => {259 return new Promise(260 (resolve) => {261 if ($('a:contains("' + ad.title + '")').length > 0) {262 resolve('edit');263 $('a:contains("' + ad.title + '")').removeAttr('target')[0].click();264 } else {265 resolve('clickNew');266 window.location.href = 'http://bbs.tigtag.com/forum.php?mod=forumdisplay&fid=' + config.fid;267 }268 });269 };270 this.edit = () => {271 return new Promise(272 (resolve) => {273 function callBack() {274 if (('a:contains("编辑")').length === 0) {275 setTimeout(callBack, 1000);276 } else {277 resolve('delete');278 $('a:contains("编辑")')[0].click();279 }280 }281 setTimeout(callBack, 1000);282 });283 };284 this.delete = () => {285 return new Promise(286 (resolve) => {287 resolve('clickNew');288 $('#delete').attr('value', '1');289 $('#postform').submit();290 });291 };292 this.clickNew = () => {293 return new Promise(294 (resolve) => {295 $('#newspecial')[0].click();296 resolve('enterNew');297 });298 };299 this.enterNew = () => {300 return new Promise(301 (resolve) => {302 $('#subject').val(ad.title);303 $('#typeid_ctrl')[0].click();304 $('#typeid_ctrl_menu>ul>li:contains("' + config.select + '")')[0].click();305 $('#e_iframe').contents().find('body').html(ad.content.replace(/\n/g, '<br/>'))306 $('#e_textarea').val(ad.content);307 $('#typeoption_money_522').val(config.rental);308 $('#typeoption_acreage_522').val(config.area);309 $('#typeoption_zftype_522:nth-of-type(1)')[1].click();310 $('#typeoption_zfhuxing_522:nth-of-type(1)')[3].click();311 $('#typeoption_water_electricity:nth-of-type(1)')[0].click();312 $('#typeoption_internet_price:nth-of-type(1)')[0].click();313 $('#typeoption_source:nth-of-type(1)')[0].click();314 $('#e_image')[0].click();315 resolve('end');316 });317 };318 this.end = () => {319 return new Promise(320 (resolve) => {321 resolve();322 });323 };324 }325 }, yiyi: {326 url: 'http://www.yeeyi.com/bbs/forum.php?mod=guide&view=my',327 init: 'link',328 ctrl: function (adId, siteId) {329 var ad = adList[adId];330 var config = ad.sites[siteId];331 this.link = () => {332 return new Promise(333 (resolve) => {334 if ($('a:contains("' + ad.title + '")').length > 0) {335 resolve('edit');336 $('a:contains("' + ad.title + '")').removeAttr('target')[0].click();337 } else {338 resolve('enterNew');339 window.location.href = 'http://www.yeeyi.com/bbs/forum.php?mod=post&action=newthread&fid=' + config.fid;340 }341 });342 };343 this.edit = () => {344 return new Promise(345 (resolve) => {346 function callBack() {347 if (('a:contains("编辑")').length === 0) {348 setTimeout(callBack, 1000);349 } else {350 resolve('delete');351 $('a:contains("编辑")')[0].click();352 }353 }354 setTimeout(callBack, 1000);355 });356 };357 this.delete = () => {358 return new Promise(359 (resolve) => {360 resolve('clickNew');361 $('#delete').attr('value', '1');362 $('#postform').submit();363 });364 };365 this.clickNew = () => {366 return new Promise(367 (resolve) => {368 resolve('enterNew');369 window.location.href = 'http://www.yeeyi.com/bbs/forum.php?mod=post&action=newthread&fid=' + config.fid;370 });371 };372 this.enterNew = () => {373 return new Promise(374 (resolve) => {375 $('input.pxe').val(ad.title);376 $('#city').val(2);377 $('#suburb').val('Killara');378 $('input[name=postcode]').val('2071');379 $('select.type').val('4');380 $('input[name=house_rents]').val(config.rental);381 $('select[name=rent_type]').val('3');382 $('input[name="house_equipment[]"][value=1]').click();383 $('input[name="house_equipment[]"][value=2]').click();384 $('input[name="house_equipment[]"][value=3]').click();385 $('input[name="house_equipment[]"][value=4]').click();386 $('input[name="house_equipment[]"][value=6]').click();387 $('input[name="house_equipment[]"][value=7]').click();388 $('input[name="house_equipment[]"][value=8]').click();389 $('input[name="house_equipment[]"][value=9]').click();390 $('input[name="house_equipment[]"][value=11]').click();391 $('input[name="house_equipment[]"][value=12]').click();392 $('input[name="bus_info[]"][value=1]').click();393 $('input[name="bus_info[]"][value=2]').click();394 $('input[name="bus_info[]"][value=3]').click();395 $('input[name="bus_info[]"][value=4]').click();396 $('input[name=poster]').val('Xuting Qiu');397 $('input[name=tel]').val('0481081960');398 $('input[name=weixin]').val('34566190');399 $('input[name=qq]').val('34566190');400 $('#e_iframe').contents().find('body').html(ad.content.replace(/\n/g, '<br/>'))401 $('#e_textarea').val(ad.content);402 $('#e_image')[0].click();403 resolve('end');404 });405 };406 this.end = () => {407 return new Promise(408 (resolve) => {409 resolve();410 });411 };412 }413 },414 didaUp: {415 url: 'http://bbs.tigtag.com/forum.php?mod=guide&view=my',416 init: 'link',417 ctrl: function (adId, siteId) {418 var ad = adList[adId];419 var config = ad.sites[siteId];420 this.link = () => {421 return new Promise(422 (resolve) => {423 if ($('a:contains("' + ad.title + '")').length > 0) {424 resolve('up');425 $('a:contains("' + ad.title + '")').removeAttr('target')[0].click();426 } else {427 resolve('clickNew');428 window.location.href = 'http://bbs.tigtag.com/forum.php?mod=forumdisplay&fid=' + config.fid;429 }430 });431 };432 this.up = () => {433 return new Promise(434 (resolve) => {435 function callBack() {436 if ($('#fastpostmessage').length === 0) {437 setTimeout(callBack, 1000);438 } else {439 $('#fastpostmessage').val('顶顶顶顶顶顶顶顶顶顶顶');440 $('#fastpostsubmit')[0].click();441 resolve('close');442 window.location.href = 'http://bbs.tigtag.com/forum.php?mod=guide&view=my';443 }444 }445 setTimeout(callBack, 1000);446 });447 };448 this.clickNew = () => {449 return new Promise(450 (resolve) => {451 $('#newspecial')[0].click();452 resolve('enterNew');453 });454 };455 this.enterNew = () => {456 var me = adList.ford;457 return new Promise(458 (resolve) => {459 $('#subject').val(ad.title);460 $('#typeid_ctrl')[0].click();461 $('#typeid_ctrl_menu>ul>li:contains("' + config.select + '")')[0].click();462 $('#e_textarea').val(ad.content);463 $('#e_image')[0].click();464 resolve('end');465 });466 };467 this.end = () => {468 return new Promise(469 (resolve) => {470 resolve(false);471 });472 };473 this.close = () => {474 return new Promise(475 (resolve) => {476 resolve(true);477 });478 };479 }480 },481 todaySydneyUp: {482 url: 'http://www.sydneytoday.com',483 init: 'up',484 ctrl: function (adId, siteId) {485 var ad = adList[adId];486 var config = ad.sites[siteId];487 this.up = () => {488 return new Promise(489 (resolve) => {490 resolve('end');491 window.location.href = 'http://www.sydneytoday.com/user/myposts';492 });493 };494 this.end = () => {495 return new Promise(496 (resolve) => {497 var button = $('div.account-itemcell-title:contains("' + ad.title + '")').parent().parent().parent().parent();498 console.log(button);499 button.find('button[data-type=rent]');500 button.click();501 //resolve(true);502 });503 };504 }505 }...

Full Screen

Full Screen

app.service.js

Source:app.service.js Github

copy

Full Screen

1import axios from 'axios'2axios.defaults.baseURL = 'http://127.0.0.1:8000/api/v1'3axios.interceptors.request.use(function (config) {4 const token = window.localStorage.getItem('token')5 if (token !== 'null') {6 config.headers.Authorization = `Token ${token}`7 }8 return config9})10const appService = {11 join (data) {12 return new Promise((resolve, reject) => {13 axios.post('/join/', data)14 .then(() => {15 resolve()16 }).catch(error => {17 reject(error.data)18 })19 })20 },21 leave (classId, userId) {22 return new Promise((resolve, reject) => {23 axios.delete(`/leave/class/${classId}/student/${userId}/`)24 .then(response => {25 resolve(response.data)26 }).catch(error => {27 reject(error.response)28 })29 })30 },31 // Quizzes32 postQuiz (data) {33 return new Promise((resolve, reject) => {34 axios.post(`/classes/${data.class_group}/quizzes/`, data)35 .then(response => {36 resolve(response.data)37 }).catch(response => {38 reject(response.status)39 })40 })41 },42 updateQuiz (data) {43 return new Promise((resolve, reject) => {44 axios.patch(`/quizzes/${data.id}/`, data)45 .then(response => {46 resolve(response.data)47 }).catch(response => {48 reject(response.status)49 })50 })51 },52 getTodayQuizzes (userId) {53 return new Promise((resolve) => {54 axios.get(`/users/${userId}/today/`)55 .then(response => {56 resolve(response.data)57 })58 })59 },60 getUserClasses (userId) {61 return new Promise((resolve) => {62 axios.get(`/users/${userId}/classes/`)63 .then(response => {64 resolve(response.data)65 })66 })67 },68 createUserClasses (data) {69 return new Promise((resolve) => {70 axios.post(`/users/${data.user}/classes/`, data)71 .then(response => {72 resolve(response.data)73 })74 })75 },76 getClassQuizzes (classId) {77 return new Promise((resolve) => {78 axios.get(`/classes/${classId}/quizzes/`)79 .then(response => {80 resolve(response.data)81 })82 })83 },84 getQuiz (quizId) {85 return new Promise((resolve) => {86 axios.get(`/quizzes/${quizId}/`)87 .then(response => {88 resolve(response.data)89 })90 })91 },92 deleteQuiz (quizId) {93 return new Promise((resolve, reject) => {94 axios.delete(`/quizzes/${quizId}/`)95 .then(response => {96 resolve(response.data)97 }).catch(error => {98 reject(error.response)99 })100 })101 },102 getClass (classId) {103 return new Promise((resolve) => {104 axios.get(`/classes/${classId}/`)105 .then(response => {106 resolve(response.data)107 })108 })109 },110 postClass (data) {111 return new Promise((resolve, reject) => {112 axios.post('/classes/', data)113 .then(response => {114 resolve(response.data)115 }).catch(response => {116 reject(response.status)117 })118 })119 },120 updateClass (classId, data) {121 return new Promise((resolve, reject) => {122 axios.patch(`/classes/${classId}/`, data)123 .then(response => {124 resolve(response.data)125 }).catch(error => {126 reject(error.response)127 })128 })129 },130 deleteClass (classId) {131 return new Promise((resolve, reject) => {132 axios.delete(`/classes/${classId}/`)133 .then(response => {134 resolve(response.data)135 }).catch(error => {136 reject(error.response)137 })138 })139 },140 // Questions141 getQuizQuestions (quiz_id) {142 return new Promise((resolve) => {143 axios.get(`/quizzes/${quiz_id}/questions/`)144 .then(response => {145 resolve(response.data)146 })147 })148 },149 postQuestion (data) {150 return new Promise((resolve, reject) => {151 axios.post(`/quizzes/${data.quiz}/questions/`, data)152 .then(response => {153 resolve(response.data)154 }).catch(response => {155 reject(response.status)156 })157 })158 },159 getQuestion (question_id) {160 return new Promise((resolve) => {161 axios.get(`/questions/${question_id}/`)162 .then(response => {163 resolve(response.data)164 })165 })166 },167 updateQuestion (questionId, data) {168 return new Promise((resolve, reject) => {169 axios.patch(`/questions/${questionId}/`, data)170 .then(response => {171 resolve(response.data)172 }).catch(error => {173 reject(error.response)174 })175 })176 },177 updateQuestionFile (questionId, data) {178 return new Promise((resolve, reject) => {179 axios.patch(`/questions/${questionId}/file/`, data)180 .then(response => {181 resolve(response.data)182 }).catch(error => {183 reject(error.response)184 })185 })186 },187 deleteQuestion (questionId) {188 return new Promise((resolve, reject) => {189 axios.delete(`/questions/${questionId}/`)190 .then(response => {191 resolve(response.data)192 }).catch(error => {193 reject(error.response)194 })195 })196 },197 deleteClass (classId) {198 return new Promise((resolve, reject) => {199 axios.delete(`/classes/${classId}/`)200 .then(response => {201 resolve(response.data)202 }).catch(error => {203 reject(error.response)204 })205 })206 },207 // Answers208 updateAnswer (answerId, data) {209 return new Promise((resolve, reject) => {210 axios.patch(`/answers/${answerId}/`, data)211 .then(response => {212 resolve(response.data)213 }).catch(error => {214 reject(error.response)215 })216 })217 },218 getQuestionAnswers (questionId) {219 return new Promise((resolve) => {220 axios.get(`/questions/${questionId}/answers/`)221 .then(response => {222 resolve(response.data)223 })224 })225 },226 postAnswer (data) {227 return new Promise((resolve, reject) => {228 axios.post(`/questions/${data.question}/answers/`, data)229 .then(response => {230 resolve(response.data)231 }).catch(error => {232 reject(error.response)233 })234 })235 },236 deleteAnswer (answerId) {237 return new Promise((resolve, reject) => {238 axios.delete(`/answers/${answerId}/`)239 .then(response => {240 resolve(response.data)241 }).catch(error => {242 reject(error.response)243 })244 })245 },246 getQuestionAndAnswers (data) {247 return new Promise((resolve, reject) => {248 axios.get(`/quizzes/${data.quiz_id}/assessment/?student=${data.student}&page=${data.page}`)249 .then(response => {250 resolve(response.data)251 }).catch(response => {252 reject(response.status)253 })254 })255 },256 getResults (quiz) {257 return new Promise((resolve, reject) => {258 axios.get(`/quizzes/${quiz}/results/`)259 .then(response => {260 resolve(response.data)261 }).catch(response => {262 reject(response.status)263 })264 })265 },266 getAssessmentResults (data) {267 return new Promise((resolve, reject) => {268 axios.get(`/quizzes/${data.quiz}/student/${data.student}/results/`)269 .then(response => {270 resolve(response.data)271 }).catch(response => {272 reject(response.status)273 })274 })275 },276 multipleChoiceResult (data) {277 return new Promise((resolve, reject) => {278 axios.post('/results/multiplechoice/', data)279 .then(response => {280 resolve(response.data)281 }).catch(error => {282 reject(error.response)283 })284 })285 },286 multipleAnswerResult (data) {287 return new Promise((resolve, reject) => {288 axios.post('/results/multipleanswer/', data)289 .then(response => {290 resolve(response.data)291 }).catch(error => {292 reject(error.response)293 })294 })295 },296 fillBlankResult (data) {297 return new Promise((resolve, reject) => {298 axios.post('/results/fillblank/', data)299 .then(response => {300 resolve(response.data)301 }).catch(error => {302 reject(error.response)303 })304 })305 },306 enumerateResult (data) {307 return new Promise((resolve, reject) => {308 axios.post('/results/enumerate/', data)309 .then(response => {310 resolve(response.data)311 }).catch(error => {312 reject(error.response)313 })314 })315 },316 doNotKnowResult (data) {317 return new Promise((resolve) => {318 axios.post('/results/donotknow/', data)319 .then(() => resolve())320 })321 },322 getUser (userId) {323 return new Promise((resolve, reject) => {324 axios.get(`/accounts/${userId}/`)325 .then(response => {326 resolve(response.data)327 }).catch(error => {328 reject(error.response)329 })330 })331 },332 login (credentials) {333 return new Promise((resolve, reject) => {334 axios.post(`/accounts/api-token-auth/`, credentials)335 .then(response => {336 resolve(response.data)337 }).catch(error => {338 reject(error.response)339 })340 })341 },342 upload (formData) {343 return new Promise((resolve, reject) => {344 axios.post(`/files/questions/${formData.question}/`, formData, {345 headers: {346 'Content-Type': 'multipart/form-data'347 }348 })349 .then(response => {350 resolve(response.data)351 }).catch(error => {352 reject(error.response)353 })354 })355 },356 getFiles (questionId) {357 return new Promise((resolve) => {358 axios.get(`/files/questions/${questionId}/`)359 .then(response => {360 resolve(response.data)361 })362 })363 },364}...

Full Screen

Full Screen

DriverController.js

Source:DriverController.js Github

copy

Full Screen

1class DriverController {2 authenticate(user) {3 return new Promise((resolve, reject) => {4 ConnectionServer.sendRequest('Driver/Authenticate', 'POST', user, resolve, reject);5 })6 }7 statusApp(appIsOpen) {8 return new Promise((resolve, reject) => {9 ConnectionServer.sendRequest('Driver/StatusApp', 'POST', {appIsOpen}, resolve, reject,undefined,false);10 })11 }12 searchTrip(driverId, listTripsDenied, location) {13 return new Promise((resolve, reject) => {14 ConnectionServer.sendRequest('Driver/searchTrip', 'POST', {15 driverId,16 listTripsDenied,17 location18 }, resolve, reject);19 });20 }21 findWithAccountInfo(driverId) {22 return new Promise((resolve, reject) => {23 ConnectionServer.sendRequest('Driver/FindWithAccountInfo', 'POST', {driverId}, resolve, reject);24 });25 }26 defaultStation(driverId, stationId) {27 return new Promise((resolve, reject) => {28 ConnectionServer.sendRequest('Driver/DefaultStation', 'POST', {driverId, stationId}, resolve, reject);29 });30 }31 acceptTrip(tripReference, driverId,estimatedTimeDriverArrival,distanceDriverArrival) {32 return new Promise((resolve, reject) => {33 ConnectionServer.sendRequest('Driver/AcceptTrip', 'POST', {34 driverId: parseInt(driverId),35 tripReference,36 estimatedTimeDriverArrival,37 distanceDriverArrival38 }, resolve, reject);39 });40 }41 toggleStatus(driverId,status,location) {42 return new Promise((resolve, reject) => {43 ConnectionServer.sendRequest('Driver/ToggleStatus', 'POST', {driverId,status,location}, resolve, reject);44 })45 }46 cancelTrip(cancelTrip) {47 return new Promise((resolve, reject) => {48 ConnectionServer.sendRequest('Driver/CancelTrip', 'POST', cancelTrip, resolve, reject);49 });50 }51 informArrival(tripReference) {52 return new Promise((resolve, reject) => {53 ConnectionServer.sendRequest('Driver/InformArrival', 'POST', {tripReference}, resolve, reject);54 });55 }56 initTrip(tripReference) {57 return new Promise((resolve, reject) => {58 ConnectionServer.sendRequest('Driver/InitTrip', 'POST', {tripReference}, resolve, reject);59 });60 }61 finishTrip(tripReference) {62 return new Promise((resolve, reject) => {63 ConnectionServer.sendRequest('Driver/FinishTrip', 'POST', {tripReference}, resolve, reject, 5000);64 });65 }66 finishTripOffline(tripReference, data) {67 return new Promise((resolve, reject) => {68 ConnectionServer.sendRequest('Driver/FinishTrip', 'POST', {tripReference, data}, resolve, reject);69 });70 }71 find(driverId) {72 return new Promise((resolve, reject) => {73 ConnectionServer.sendRequest('Driver/Find', 'POST', {driverId}, resolve, reject);74 });75 }76 sendConfirmationCode(number) {77 return new Promise(resolve => {78 ConnectionServer.sendRequest('Driver/SendConfirmationCode', 'POST', {number}, resolve);79 })80 }81 refuseTrip(driverId, tripReference) {82 return new Promise(resolve => {83 ConnectionServer.sendRequest('Driver/RefuseTrip', 'POST', {driverId, tripReference}, resolve);84 })85 }86 register(driver) {87 return new Promise(resolve => {88 const formData = new FormData();89 FileUpload.prepare(driver.image.CNH).then(file => {90 formData.append("CNH", file.data, file.name);91 });92 FileUpload.prepare(driver.image.CRLV).then(file => {93 formData.append("CRLV", file.data, file.name);94 });95 if (driver.image.ALVARA !== null)96 FileUpload.prepare(driver.image.ALVARA).then(file => {97 formData.append("ALVARA", file.data, file.name)98 });99 FileUpload.prepare(driver.image.PROFILE).then(file => {100 formData.append("PROFILE", file.data, file.name)101 });102 if (driver.image.CRIMINAL_RECORD !== null)103 FileUpload.prepare(driver.image.CRIMINAL_RECORD).then(file => {104 formData.append("CRIMINAL_RECORD", file.data, file.name);105 });106 formData.append("stdObject", JSON.stringify(driver));107 setTimeout(function () {108 ConnectionServer.sendRequestWithFiles("Driver/Register", "POST", formData).then(resolve);109 }, 500);110 });111 }112 getTripsById(driverId, page, date = null, status = null) {113 return new Promise(resolve => {114 ConnectionServer.sendRequest('Driver/GetTrips', 'POST', {driverId, page, date, status}, resolve)115 })116 }117 static checkPassword(password){118 return new Promise((resolve,reject) => {119 ConnectionServer.sendRequest('Driver/CheckPassword', 'POST', {password}, resolve,reject,undefined,false);120 });121 }122 static getCodeVerify(email) {123 return new Promise(resolve => {124 ConnectionServer.sendRequest('Driver/ForgotPassword', 'POST', {email}, resolve);125 });126 }127 static updatePasswordById(email, password) {128 return new Promise(resolve => {129 ConnectionServer.sendRequest('Driver/ChangePassword', 'POST', {email, password}, resolve);130 });131 }132 static updateDataDriver(driver) {133 return new Promise(resolve => {134 ConnectionServer.sendRequest('Driver/Edit', 'POST', {135 ...driver136 }, resolve);137 });138 }139 static updatePhoto(driverId, photo) {140 return new Promise(resolve => {141 const formData = new FormData();142 FileUpload.prepare(photo).then(file => {143 formData.append("photo", file.data, file.name);144 formData.append("driverId", driverId);145 ConnectionServer.sendRequestWithFiles("Driver/EditProfileImage", "POST", formData).then(resolve);146 });147 });148 }149 /**150 *151 * @param email152 * @returns {Promise<any>}153 */154 checkEmail(email) {155 return new Promise(resolve => {156 ConnectionServer.sendRequest('Driver/CheckEmail', 'POST', {email}, resolve);157 });158 }159 updateVersion(driverId, driverAppVersion,deviceToken) {160 return new Promise((resolve, reject) => {161 ConnectionServer.sendRequest('Driver/UpdateVersion', 'POST', {driverId, driverAppVersion,deviceToken}, resolve, reject,162 undefined, false);163 })164 }165 static checkCpf(data) {166 return new Promise((resolve, reject) => {167 ConnectionServer.sendRequest('Driver/CheckDocument', 'POST', data, resolve, reject, undefined, false);168 });169 }170 putPreAvailable(){171 return new Promise((resolve, reject) => {172 ConnectionServer.sendRequest('Driver/PutPreAvailable', 'POST', {}, resolve, reject);173 });174 }175 static confirmWaypoint(idWayPoint){176 return new Promise((resolve, reject) => {177 ConnectionServer.sendRequest('Driver/ConfirmWaypoint', 'POST', {idWayPoint}, resolve, reject,undefined,false);178 });179 }...

Full Screen

Full Screen

promise.js

Source:promise.js Github

copy

Full Screen

1const groupId = process.argv[2]2const caseId = process.argv[3]3if (groupId == 0) {4 /**5 * new Promise(resolve, reject) 只会创建一个promise对象, 并不会立即执行6 */7 console.log(new Promise(resolve => resolve(1))) // Promise { 1 }8}9if (groupId == 1) {10 /**11 * 同case012 */13 console.log(Promise.resolve(1)) // Promise { 1 }14}15if (groupId == 2) {16 /**17 * .then 过后会promise的状态会变为pending(需要后续操作)18 */19 const pending = Promise.resolve(1)20 .then(x => console.log(x))21 if (caseId == 2) {22 console.log(pending) // Promise { <pending> }23 }24}25if (groupId == 3) {26 if (caseId == 1) { /**27 * promise的数据可以链式传递, 只要promise到达了fulfill状态, 就会继续传递下去28 * 在then状态中返回一个数据, promise会直接进入fulfill状态29 */30 Promise.resolve(1)31 .then(x => {32 console.log(x) // 133 return x + 134 })35 .then(x => console.log(x)) // 236 }37 if (caseId == 2) {38 console.log(39 Promise.resolve(1)40 .then(x => x + 1)41 ) // Promise { <pending> }42 }43 /**44 * 可以使用async await将一个promise同步化45 */46 if (caseId == 3) {47 async function asyncTest() {48 console.log(49 await Promise.resolve(1)50 .then(x => x + 1)51 )52 }53 asyncTest()54 }55}56if (groupId == 3) {57 if (caseId == 1) {58 /**59 * promise可以继续传递promise60 */61 Promise.resolve(1)62 .then(x => Promise.resolve(x + 1))63 .then(x => console.log(x)) // 264 }65 if (caseId == 2) {66 Promise.resolve(1)67 .then(x => {68 return Promise.resolve(x + 1).then(y => console.log(y)) // 269 })70 .then(x => console.log(x)) // undefined71 }72 if (caseId == 3) {73 Promise.resolve(1)74 .then(x =>75 Promise.all([76 Promise.resolve(11),77 Promise.resolve(12),78 Promise.resolve(13),79 Promise.resolve(14),80 ])81 )82 .then(x => console.log(x)) // [ 11, 12, 13, 14 ]83 }84 if (caseId == 4) {85 Promise.resolve(1).then(x =>86 Promise.all([87 Promise.resolve(11),88 Promise.resolve(12),89 Promise.resolve(13),90 Promise.reject(14),91 ])92 )93 .then(x => console.log(x))94 .catch(x => console.log(x)) // [ 14 ]95 }96 if (caseId == 5) {97 Promise.reject(1)98 .then(x => console.log(x))99 .catch(x => console.log(x)) // 1100 }101 if (caseId == 6) {102 Promise.reject(1)103 .then(x => Promise.all([104 Promise.resolve(11),105 Promise.resolve(12),106 Promise.resolve(13),107 Promise.resolve(14),108 ]))109 .then(x => console.log(x))110 .catch(x => console.log(x)) // 1111 }112 if (caseId == 7) {113 Promise.resolve(1)114 .then(x => Promise.all([115 Promise.resolve(11),116 Promise.resolve(12),117 Promise.resolve(13),118 Promise.reject(14),119 ]))120 .then(x => console.log(x))121 .catch(x => console.log(x)) // 14122 }...

Full Screen

Full Screen

api.js

Source:api.js Github

copy

Full Screen

1import { promises } from 'dns'2export const getUser = jest.fn(() => Promise.resolve([]))3export const putUser = jest.fn(() => Promise.resolve([]))4export const postLogin = jest.fn(() => Promise.resolve([]))5export const postSignup = jest.fn(() => Promise.resolve([]))6export const getChecklists = jest.fn(() => promises.resolve([]))7export const getChecklist = jest.fn(() => Promise.resolve([]))8export const postChecklist = jest.fn(() => Promise.resolve([]))9export const putChecklist = jest.fn(() => Promise.resolve([]))10export const deleteChecklist = jest.fn(() => Promise.resolve([]))11export const getContacts = jest.fn(() => Promise.resolve([]))12export const getContact = jest.fn(() => Promise.resolve([]))13export const postContact = jest.fn(() => Promise.resolve([]))14export const putContact = jest.fn(() => Promise.resolve([]))15export const deleteContact = jest.fn(() => Promise.resolve([]))16export const getItems = jest.fn(() => Promise.resolve([]))17export const getItem = jest.fn(() => Promise.resolve([]))18export const postItem = jest.fn(() => Promise.resolve([]))19export const putItem = jest.fn(() => Promise.resolve([]))20export const deleteItem = jest.fn(() => Promise.resolve([]))21export const getLocations = jest.fn(() => Promise.resolve([]))22export const getLocation = jest.fn(() => Promise.resolve([]))23export const postLocation = jest.fn(() => Promise.resolve([]))24export const putLocation = jest.fn(() => Promise.resolve([]))25export const deleteLocation = jest.fn(() => Promise.resolve([]))26export const postSetRelationship = jest.fn(() => Promise.resolve([]))27export const getAppData = jest.fn(() => Promise.resolve([]))...

Full Screen

Full Screen

amqplibMock.js

Source:amqplibMock.js Github

copy

Full Screen

1exports.mock = function () {2 var _methods = {};3 var _helpers = {4 consumerTag: "3408c524309c57n2105",5 closeConnection: (err) => closeFn(err)6 };7 var closeFn = null;8 9 return {10 _methods: _methods,11 _helpers: _helpers,12 create: function () {13 var amqp = {14 connect: () => Promise.resolve(connection)15 };16 var connection = {17 createChannel: () => Promise.resolve(channel),18 close: () => Promise.resolve(),19 on: (name, fn) => { if(name === 'close') closeFn = fn; }20 };21 var channel = {22 assertExchange: () => Promise.resolve( {exchange: "testExchange"} ),23 assertQueue: () => Promise.resolve( {queue: "testQueue"} ),24 checkQueue: () => Promise.resolve( {queue: "testQueue"} ),25 checkExchange: () => Promise.resolve( {queue: "testQueue"} ),26 unbindQueue: () => Promise.resolve(),27 bindQueue: () => Promise.resolve(),28 close: () => Promise.resolve(),29 ack: () => Promise.resolve(),30 nack: () => Promise.resolve(),31 prefetch: () => Promise.resolve(),32 publish: () => Promise.resolve(),33 consume: () => Promise.resolve({consumerTag: _helpers.consumerTag}),34 cancel: () => Promise.resolve()35 };36 _methods.amqp = amqp;37 _methods.connection = connection;38 _methods.channel = channel;39 40 return Promise.resolve(amqp);41 }42 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var Promise = require("bluebird");2var sinon = require("sinon");3var chai = require("chai");4var expect = chai.expect;5var assert = chai.assert;6var fs = require("fs");7var path = require("path");8var proxyquire = require("proxyquire");9var sinonPromise = require("sinon-promise");10sinonPromise(sinon);11var file = path.join(__dirname, "file.js");12var fsStub = sinon.stub(fs, "readFile");13var fsPromiseStub = sinonPromise.stub(fs, "readFile");14fsStub.yields(null, "file content");15fsPromiseStub.resolves("file content");16var fileToTest = proxyquire(file, { fs: fsStub });17var fileToTestPromise = proxyquire(file, { fs: fsPromiseStub });18describe("Test file", function() {19 it("should return file content", function(done) {20 fileToTest(function(err, data) {21 expect(err).to.not.exist;22 expect(data).to.equal("file content");23 done();24 });25 });26 it("should return file content using promise", function() {27 return fileToTestPromise().then(function(data) {28 expect(data).to.equal("file content");29 });30 });31});32var fs = require("fs");33module.exports = function(callback) {34 fs.readFile("file.txt", "utf8", function(err, data) {35 if (err) {36 return callback(err);37 }38 callback(null, data);39 });40};

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var Promise = require('bluebird');3var chai = require('chai');4var expect = chai.expect;5var assert = chai.assert;6var request = require('request');7var stub = sinon.stub(request, 'get');8var data = {9};10stub.yields(null, data);11var get = Promise.promisify(request.get);12var test = function () {13 console.log(data);14 });15}16test();17var sinon = require('sinon');18var Promise = require('bluebird');19var chai = require('chai');20var expect = chai.expect;21var assert = chai.assert;22var request = require('request');23var stub = sinon.stub(request, 'get');24var data = {25};26stub.yields(null, data);27var get = Promise.promisify(request.get);28var test = function () {29 console.log(data);30 });31}32describe('Test', function () {33 it('should pass', function () {34 return test().then(function (data) {35 assert.equal(data, data);36 });37 });38});39var sinon = require('sinon');40var Promise = require('bluebird');41var chai = require('chai');42var expect = chai.expect;43var assert = chai.assert;44var request = require('request');45var stub = sinon.stub(request, 'get');46var data = {47};48stub.yields(null, data);49var get = Promise.promisify(request.get);50var test = function () {51 console.log(data);52 });53}54describe('Test', function () {55 it('should pass', function () {56 return test().then(function (data) {57 assert.equal(data, data);58 });59 });60});61var sinon = require('sinon');62var Promise = require('bluebird');63var chai = require('chai');64var expect = chai.expect;65var assert = chai.assert;66var request = require('request');

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var Promise = require('bluebird');3var myLib = require('./myLib');4describe('myLib', function() {5 it('should return a promise', function() {6 var stub = sinon.stub(myLib, 'myLibFunction').returns(Promise.resolve('test'));7 return myLib.myLibFunction().then(function(result) {8 expect(result).to.equal('test');9 });10 });11});12var Promise = require('bluebird');13var myLib = {14 myLibFunction: function() {15 return Promise.resolve('test');16 }17};18module.exports = myLib;19Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/username/Documents/Projects/myProject/test/test.js)20var sinon = require('sinon');21var Promise = require('bluebird');22var myLib = require('./myLib');23describe('myLib', function() {24 it('should return a promise', function() {25 var stub = sinon.stub(myLib, 'myLibFunction').returns(Promise.resolve('test'));26 return myLib.myLibFunction().then(function(result) {27 expect(result).to.equal('test');28 });29 });30});31var Promise = require('bluebird');32var myLib = {33 myLibFunction: function() {34 return Promise.resolve('test');35 }36};37module.exports = myLib;

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var Promise = require('bluebird');3var chai = require('chai');4var expect = chai.expect;5var should = chai.should();6var test = require('../test.js');7var testObj = new test();8describe('test', function() {9 it('should return success', function() {10 var stub = sinon.stub(Promise, 'resolve').returns(Promise.resolve('success'));11 testObj.test().then(function(data) {12 expect(data).to.equal('success');13 });14 stub.restore();15 });16});17var Promise = require('bluebird');18var test = function() {19 this.test = function() {20 return Promise.resolve('success');21 }22}23module.exports = test;24var sinon = require('sinon');25var Promise = require('bluebird');26var chai = require('chai');27var expect = chai.expect;28var should = chai.should();29var test = require('../test.js');30var testObj = new test();31describe('test', function() {32 it('should return success', function() {33 var stub = sinon.stub(Promise, 'resolve').returns(Promise.resolve('success'));34 testObj.test().then(function(data) {35 expect(data).to.equal('success');36 });37 stub.restore();38 });39});40var Promise = require('bluebird');41var test = function() {42 this.test = function() {43 return Promise.resolve('success');44 }45}46module.exports = test;

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4var moduleToTest = require('./moduleToTest.js');5describe('moduleToTest', function() {6 it('should return the value from the promise', function() {7 var expectedValue = 'expectedValue';8 var promiseStub = sinon.stub().returns(Promise.resolve(expectedValue));9 sinon.stub(moduleToTest, 'functionToTest', promiseStub);10 moduleToTest.functionToTest().then(function(value) {11 expect(value).to.equal(expectedValue);12 });13 });14});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var test = require('./test');4describe('test', function() {5 it('should return a promise', function() {6 var stub = sinon.stub(test, 'test');7 stub.returns(Promise.resolve({}));8 return test.test().then(function(data) {9 assert(data);10 });11 });12});13var test = function() {14 return new Promise(function(resolve, reject) {15 resolve({});16 });17}18module.exports = {19}20it('should call callback with correct arguments', function () {21 var callback = sinon.spy();22 myFunction(callback);23 expect(callback).to.have.been.calledWith('foo', 'bar');24});25it('should call callback with correct arguments', function () {26 var callback = sinon.spy();27 myFunction(callback);28 expect(callback).to.have.been.calledWith('foo', 'bar');29});30it('should call callback with correct arguments', function () {31 var callback = sinon.spy();32 myFunction(callback);33 expect(callback).to.have.been.calledWith('foo', 'bar');34});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4var moduleToTest = require('./moduleToTest.js');5describe('moduleToTest', function() {6 it('should return the value from the promise', function() {7 var expectedValue = 'expectedValue';8 var promiseStub = sinon.stub().returns(Promise.resolve(expectedValue));9 sinon.stub(moduleToTest, 'functionToTest', promiseStub);10 moduleToTest.functionToTest().then(function(value) {11 expect(value).to.equal(expectedValue);12 });13 });14});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var test = require('./test');4describe('test', function() {5 it('should return a promise', function() {6 var stub = sinon.stub(test, 'test');7 stub.returns(Promise.resolve({}));8 return test.test().then(function(data) {9 assert(data);10 });11 });12});13var test = function() {14 return new Promise(function(resolve, reject) {15 resolve({});16 });17}18module.exports = {19}20it('should call callback with correct arguments', function () {21 var callback = sinon.spy();22 myFunction(callback);23 expect(callback).to.have.been.calledWith('foo', 'bar');24});25it('should call callback with correct arguments', function () {26 var callback = sinon.spy();27 myFunction(callback);28 expect(callback).to.have.been.calledWith('foo', 'bar');29});30it('should call callback with correct arguments', function () {31 var callback = sinon.spy();32 myFunction(callback);33 expect(callback).to.have.been.calledWith('foo', 'bar');34});

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 sinon 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