Best JavaScript code snippet using root
group.js
Source:group.js
1import _ from 'lodash';2import Promise from 'bluebird';3import bumpVersion from 'bump-regex';4import Directory from './directory';5import {DirectorySkippedError, InvalidVersionError} from './errors';6const VersionRegexp = new RegExp('^\\d+\\.\\d+\\.\\d+(?:-\\w+(?:\\.\\d+)?)?$');7const bumpVersionAsync = Promise.promisify(bumpVersion);8/**9 * Represents a group of directories.10 * Either the specified directory or the current working directory.11 * @constructor12 * @param {Object} config - a config object.13 * @param {string} config.name - the group name.14 * @param {Object|string[]} members - either a directory path or a config object.15 * @param {boolean} allowEmptyRelease - wether or not allow empty release.16 */17export default class Group {18 constructor({ name, members = [], allowEmptyRelease = true }) {19 this.name = name;20 this.allowEmptyRelease = !!allowEmptyRelease;21 this.members = _.map(members, (member) => {22 return new Directory(member);23 });24 }25 /**26 * Runs git status27 * @return {Promise}28 */29 status() {30 return Promise.map(this.members, (member) => {31 return member32 .status()33 .catch((error) => {34 return {isRejected: true, parent: member, error};35 });36 });37 }38 /**39 * Runs both git status & member.getVersion(),40 * merges the result41 * @return {Promise}42 */43 detailedStatus() {44 return Promise.map(this.members, (member) => {45 return member46 .detailedStatus()47 .catch((error) => {48 return {isRejected: true, parent: member, error};49 });50 });51 }52 /**53 * Runs git fetch54 * @return {Promise}55 */56 fetch() {57 return Promise.map(this.members, (member) => {58 return member59 .fetch()60 .catch((error) => {61 return {isRejected: true, parent: member, error};62 });63 });64 }65 /**66 * Runs git checkout67 * @param {string} what - what to checkout68 * @return {Promise}69 */70 checkout(what) {71 return Promise.map(this.members, (member) => {72 return member73 .checkout(what)74 .catch((error) => {75 return {isRejected: true, parent: member, error};76 });77 });78 }79 /**80 * Runs git commit81 * @param {string} messgae - the commit message82 * @return {Promise}83 */84 commit(message) {85 return Promise.map(this.members, (member) => {86 return member87 .commit(message)88 .catch((error) => {89 return {isRejected: true, parent: member, error};90 });91 });92 }93 /**94 * Runs git branch95 * @return {Promise}96 */97 branch() {98 return Promise.map(this.members, (member) => {99 return member100 .branch()101 .catch((error) => {102 return {isRejected: true, parent: member, error};103 });104 });105 }106 /**107 * Runs git branch -d108 * @param {string} branchName - the name of the branch to delete109 * @return {Promise}110 */111 deleteBranch(branchName) {112 return Promise.map(this.members, (member) => {113 return member114 .deleteBranch(branchName)115 .catch((error) => {116 return {isRejected: true, parent: member, error};117 });118 });119 }120 /**121 * Runs git branch122 * @param {string} branchName - the name of the branch to create123 * @param {string} startPoint - the branch starting point124 * @return {Promise}125 */126 createBranch(branchName, startPoint) {127 return Promise.map(this.members, (member) => {128 return member129 .createBranch(branchName, startPoint)130 .catch((error) => {131 return {isRejected: true, parent: member, error};132 });133 });134 }135 /**136 * Runs git push137 * @param {string} remoteName - the remote name to push to138 * @param {string} branchName - the branch name to push139 * @return {Promise}140 */141 push(remoteName, branchName) {142 return Promise.map(this.members, (member) => {143 return member144 .push(remoteName, branchName)145 .then(() => {146 return {isRejected: false, parent: member};147 })148 .catch((error) => {149 return {isRejected: true, parent: member, error};150 });151 });152 }153 /**154 * Runs git push155 * @param {string} remoteName - the remote name to push to156 * @return {Promise}157 */158 pushTags(remoteName) {159 return Promise.map(this.members, (member) => {160 return member161 .pushTags(remoteName)162 .then(() => {163 return {isRejected: false, parent: member};164 })165 .catch((error) => {166 return {isRejected: true, parent: member, error};167 });168 });169 }170 /**171 * Runs git pull172 * @param {string} remoteName - the remote name to pull from173 * @param {string} branchName - the branch name to pull174 * @param {Array} options - a string array of git pull options175 * @return {Promise}176 */177 pull(remoteName, branchName, options) {178 return Promise.map(this.members, (member) => {179 return member180 .pull(remoteName, branchName, options)181 .catch((error) => {182 return {isRejected: true, parent: member, error};183 });184 });185 }186 /**187 * Runs git merge188 * @param {string} from - where to merge from (commit hash, branch name)189 * @param {string} to - where to merge to (commit hash, branch name)190 * @param {Array} options - a string array of git merge options191 * @return {Promise}192 */193 mergeFromTo(from, to, options) {194 return Promise.map(this.members, (member) => {195 return member196 .mergeFromTo(from, to, options)197 .catch((error) => {198 return {isRejected: true, parent: member, error};199 });200 });201 }202 /**203 * Creates a tag204 * @param {string} tagName - the tag name205 * @param {string} tagMessage - the tag message206 * @return {Promise}207 */208 tag(tagName, tagMessage) {209 return Promise.map(this.members, (member) => {210 return member211 .tag(tagName, tagMessage)212 .catch((error) => {213 return {isRejected: true, parent: member, error};214 });215 });216 }217 /**218 * Stages files219 * @param {Array} files - the files to stage220 * @return {Promise}221 */222 addFiles(files) {223 return Promise.map(this.members, (member) => {224 return member225 .addFiles(files)226 .then(() => {227 return {isRejected: false, parent: member};228 })229 .catch((error) => {230 return {isRejected: true, parent: member, error};231 });232 });233 }234 /**235 * Unstages files236 * @param {Array} files - the files to stage237 * @return {Promise}238 */239 unstageFiles(files) {240 return Promise.map(this.members, (member) => {241 return member242 .reset(['HEAD', ...files])243 .then(() => {244 return {isRejected: false, parent: member};245 })246 .catch((error) => {247 return {isRejected: true, parent: member, error};248 });249 });250 }251 /**252 * Stash the working directory253 * @param {Array} options - array of options supported by the git stash command254 * @return {Promise}255 */256 stash(options) {257 return Promise.map(this.members, (member) => {258 return member259 .stash(options)260 .then(() => {261 return {isRejected: false, parent: member};262 })263 .catch((error) => {264 return {isRejected: true, parent: member, error};265 });266 });267 }268 /**269 * [git flow] Ensures there is no active release270 * @return {Promise}271 */272 ensureNoActiveRelease() {273 return Promise.map(this.members, (member) => {274 return member275 .ensureNoActiveRelease()276 .then((success) => {277 return {success, parent: member};278 })279 .catch((error) => {280 return {isRejected: true, parent: member, error};281 });282 });283 }284 /**285 * [git flow] Pushes master, develop & tags to origin286 * @return {Promise}287 */288 pushAllDefaults() {289 return Promise.map(this.members, (member) => {290 return member291 .pushAllDefaults()292 .then(() => {293 return {isRejected: false, parent: member};294 })295 .catch((error) => {296 return {isRejected: true, parent: member, error};297 });298 });299 }300 /**301 * Gets the status and throws errors if the repository is either dirty, ahead or behind its remote302 * @return {Promise}303 */304 ensureCleanState() {305 return Promise.map(this.members, (member) => {306 return member307 .ensureCleanState()308 .then(() => {309 return {isRejected: false, parent: member};310 })311 .catch((error) => {312 return {isRejected: true, parent: member, error};313 });314 });315 }316 /**317 * [git flow] Gets the group latest version318 * @param {string} bump - the version bump, can be any valid semver319 * @return {Promise}320 */321 getNextVersion(bump = 'patch') {322 return this323 .getLatestVersion()324 .then((version) => {325 if (VersionRegexp.test(bump)) {326 return bump;327 } else if (_.isNil(bump) || _.indexOf(['major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', 'prerelease'], bump) !== -1) {328 return bumpVersionAsync({str: `version: ${version}`, type: bump})329 .then((result) => {330 return result.new;331 })332 .catch((error) => {333 throw new InvalidVersionError(error);334 });335 } else {336 throw new InvalidVersionError();337 }338 });339 }340 /**341 * [git flow] Gets the group latest version342 * @return {Promise}343 */344 getLatestVersion() {345 return Promise.map(this.members, (member) => {346 return member.getVersion();347 })348 .then((versions) => {349 versions.sort();350 return _.last(versions);351 });352 }353 /**354 * [git flow] Starts a new feature355 * @param {string} name - the feature name356 * @param {string} base - an optional base for the feature, instead of develop357 * @return {Promise}358 */359 featureStart(name, base) {360 return Promise.map(this.members, (member) => {361 return member362 .featureStart(name, base)363 .then(() => {364 return {isRejected: false, parent: member};365 })366 .catch((error) => {367 return {isRejected: true, parent: member, error};368 });369 });370 }371 /**372 * [git flow] Publishes the current feature373 * @param {string} name - the feature name374 * @return {Promise}375 */376 featurePublish(name) {377 return Promise.map(this.members, (member) => {378 return member379 .featurePublish(name)380 .then(() => {381 return {isRejected: false, parent: member};382 })383 .catch((error) => {384 return {isRejected: true, parent: member, error};385 });386 });387 }388 /**389 * [git flow] Finishes the current feature390 * @param {string} name - the feature name391 * @return {Promise}392 */393 featureFinish(name) {394 return Promise.map(this.members, (member) => {395 return member396 .featureFinish(name)397 .then(() => {398 return {isRejected: false, parent: member};399 })400 .catch((error) => {401 return {isRejected: true, parent: member, error};402 });403 });404 }405 /**406 * [git flow] Starts a new release407 * @param {string} name - the release name408 * @param {string} base - an optional base for the release, instead of develop409 * @return {Promise}410 */411 releaseStart(name, base) {412 return Promise.map(this.members, (member) => {413 return member414 .releaseStart(name, base)415 .then(() => {416 return {isRejected: false, parent: member};417 })418 .catch((error) => {419 return {isRejected: true, parent: member, error};420 });421 });422 }423 /**424 * [git flow] Starts a new release for directories where develop is ahead of master425 * @param {string} name - the release name426 * @param {string} base - an optional base for the release, instead of develop427 * @return {Promise}428 */429 filteredReleaseStart(name, base) {430 return Promise.map(this.members, (member) => {431 return member432 .isNextReleaseWorthCreating(base)433 .then((result) => {434 if (result) {435 return member.releaseStart(name, base);436 }437 throw new DirectorySkippedError('Nothing to commit.');438 })439 .then(() => {440 return {isRejected: false, parent: member};441 })442 .catch((error) => {443 if (error.code === 'directory-skipped') {444 return {isRejected: true, isWarned: true, parent: member, error};445 }446 return {isRejected: true, parent: member, error};447 });448 });449 }450 /**451 * [git flow] Publishes the current release452 * @param {string} name - the release name453 * @return {Promise}454 */455 releasePublish(name) {456 return Promise.map(this.members, (member) => {457 return member458 .releasePublish(name)459 .then(() => {460 return {isRejected: false, parent: member};461 })462 .catch((error) => {463 return {isRejected: true, parent: member, error};464 });465 });466 }467 /**468 * [git flow] Finishes the current release469 * @param {string} name - the release name470 * @return {Promise}471 */472 releaseFinish(name) {473 return Promise.map(this.members, (member) => {474 return member475 .releaseFinish(name)476 .then(() => {477 return {isRejected: false, parent: member};478 })479 .catch((error) => {480 return {isRejected: true, parent: member, error};481 });482 });483 }484 /**485 * [git flow] Starts a new hotfix486 * @param {string} name - the hotfix name487 * @param {string} base - an optional base for the hotfix, instead of develop488 * @return {Promise}489 */490 hotfixStart(name, base) {491 return Promise.map(this.members, (member) => {492 return member493 .hotfixStart(name, base)494 .then(() => {495 return {isRejected: false, parent: member};496 })497 .catch((error) => {498 return {isRejected: true, parent: member, error};499 });500 });501 }502 /**503 * [git flow] Publishes the current hotfix504 * @param {string} name - the hotfix name505 * @return {Promise}506 */507 hotfixPublish(name) {508 return Promise.map(this.members, (member) => {509 return member510 .hotfixPublish(name)511 .then(() => {512 return {isRejected: false, parent: member};513 })514 .catch((error) => {515 return {isRejected: true, parent: member, error};516 });517 });518 }519 /**520 * [git flow] Finishes the current hotfix521 * @param {string} name - the hotfix name522 * @return {Promise}523 */524 hotfixFinish(name) {525 return Promise.map(this.members, (member) => {526 return member527 .hotfixFinish(name)528 .then(() => {529 return {isRejected: false, parent: member};530 })531 .catch((error) => {532 return {isRejected: true, parent: member, error};533 });534 });535 }536 /**537 * [git flow] Starts a new bugfix538 * @param {string} name - the bugfix name539 * @param {string} base - an optional base for the bugfix, instead of develop540 * @return {Promise}541 */542 bugfixStart(name, base) {543 return Promise.map(this.members, (member) => {544 return member545 .bugfixStart(name, base)546 .then(() => {547 return {isRejected: false, parent: member};548 })549 .catch((error) => {550 return {isRejected: true, parent: member, error};551 });552 });553 }554 /**555 * [git flow] Publishes the current bugfix556 * @param {string} name - the bugfix name557 * @return {Promise}558 */559 bugfixPublish(name) {560 return Promise.map(this.members, (member) => {561 return member562 .bugfixPublish(name)563 .then(() => {564 return {isRejected: false, parent: member};565 })566 .catch((error) => {567 return {isRejected: true, parent: member, error};568 });569 });570 }571 /**572 * [git flow] Finishes the current bugfix573 * @param {string} name - the bugfix name574 * @return {Promise}575 */576 bugfixFinish(name) {577 return Promise.map(this.members, (member) => {578 return member579 .bugfixFinish(name)580 .then(() => {581 return {isRejected: false, parent: member};582 })583 .catch((error) => {584 return {isRejected: true, parent: member, error};585 });586 });587 }588 /**589 * [git flow] Starts a new support590 * @param {string} name - the support name591 * @param {string} base - a base for the support592 * @return {Promise}593 */594 supportStart(name, base) {595 return Promise.map(this.members, (member) => {596 return member597 .supportStart(name, base)598 .then(() => {599 return {isRejected: false, parent: member};600 })601 .catch((error) => {602 return {isRejected: true, parent: member, error};603 });604 });605 }606 /**607 * [git flow] Publishes the current support608 * @param {string} name - the support name609 * @return {Promise}610 */611 supportPublish(name) {612 return Promise.map(this.members, (member) => {613 return member614 .supportPublish(name)615 .then(() => {616 return {isRejected: false, parent: member};617 })618 .catch((error) => {619 return {isRejected: true, parent: member, error};620 });621 });622 }...
assert-promise-specific.js
Source:assert-promise-specific.js
...43 op: () => assert.doesNotBecome(promise, { foo: "bar" }, custom),44 message: custom45 });46 });47 describe(".isRejected(promise)", () => {48 shouldFail({49 op: () => assert.isRejected(promise),50 message: "to be rejected"51 });52 });53 describe(".isRejected(promise, TypeError)", () => {54 shouldFail({55 op: () => assert.isRejected(promise, TypeError),56 message: "to be rejected"57 });58 });59 describe(".isRejected(promise, /regexp/)", () => {60 shouldFail({61 op: () => assert.isRejected(promise, /regexp/),62 message: "to be rejected"63 });64 });65 describe(".isRejected(promise, TypeError, /regexp/)", () => {66 shouldFail({67 op: () => assert.isRejected(promise, TypeError, /regexp/),68 message: "to be rejected"69 });70 });71 describe(".isRejected(promise, errorInstance)", () => {72 shouldFail({73 op: () => assert.isRejected(promise, error),74 message: "to be rejected"75 });76 });77 // Chai never interprets the 3rd parameter to assert.throws as78 // a custom error message. This is what we are checking here.79 describe(".isRejected(promise, /quux/, custom)", () => {80 shouldFail({81 op: () => assert.isRejected(promise, /quux/, custom),82 notMessage: custom83 });84 });85 });86 describe("when the promise is rejected", () => {87 beforeEach(() => {88 promise = Promise.reject(error);89 });90 describe(".isFulfilled(promise)", () => {91 shouldFail({92 op: () => assert.isFulfilled(promise),93 message: "to be fulfilled"94 });95 });96 describe(".isFulfilled(promise, custom)", () => {97 shouldFail({98 op: () => assert.isFulfilled(promise, custom),99 message: custom100 });101 });102 describe(".isRejected(promise)", () => {103 shouldPass(() => assert.isRejected(promise));104 });105 describe(".isRejected(promise, theError)", () => {106 shouldPass(() => assert.isRejected(promise, error));107 });108 describe(".isRejected(promise, differentError)", () => {109 shouldFail({110 op: () => assert.isRejected(promise, new Error()),111 message: "to be rejected with"112 });113 });114 // Chai never interprets the 3rd parameter to assert.throws as115 // a custom error message. This is what we are checking here.116 describe(".isRejected(promise, differentError, custom)", () => {117 shouldFail({118 op: () => assert.isRejected(promise, new Error(), custom),119 notMessage: custom120 });121 });122 describe("with an Error having message 'foo bar'", () => {123 beforeEach(() => {124 promise = Promise.reject(new Error("foo bar"));125 });126 describe(".isRejected(promise, 'bar')", () => {127 shouldPass(() => assert.isRejected(promise, "bar"));128 });129 describe(".isRejected(promise, 'bar', custom)", () => {130 shouldPass(() => assert.isRejected(promise, "bar", custom));131 });132 describe(".isRejected(promise, /bar/)", () => {133 shouldPass(() => assert.isRejected(promise, /bar/));134 });135 describe(".isRejected(promise, /bar/, custom)", () => {136 shouldPass(() => assert.isRejected(promise, /bar/, custom));137 });138 describe(".isRejected(promise, 'quux')", () => {139 shouldFail({140 op: () => assert.isRejected(promise, "quux"),141 message: "to be rejected with"142 });143 });144 // Chai 3.5.0 never interprets the 3rd parameter to assert.throws as145 // a custom error message. This is what we are checking here.146 describe(".isRejected(promise, 'quux', custom)", () => {147 shouldFail({148 op: () => assert.isRejected(promise, "quux", custom),149 notMessage: custom150 });151 });152 describe(".isRejected(promise, /quux/)", () => {153 shouldFail({154 op: () => assert.isRejected(promise, /quux/),155 message: "to be rejected with"156 });157 });158 });159 describe("with a RangeError", () => {160 beforeEach(() => {161 promise = Promise.reject(new RangeError());162 });163 describe(".isRejected(promise, RangeError)", () => {164 shouldPass(() => assert.isRejected(promise, RangeError));165 });166 describe(".isRejected(promise, TypeError)", () => {167 shouldFail({168 op: () => assert.isRejected(promise, TypeError),169 message: "to be rejected"170 });171 });172 });173 describe("with a RangeError having a message 'foo bar'", () => {174 beforeEach(() => {175 promise = Promise.reject(new RangeError("foo bar"));176 });177 describe(".isRejected(promise, RangeError, 'foo')", () => {178 shouldPass(() => assert.isRejected(promise, RangeError, "foo"));179 });180 describe(".isRejected(promise, RangeError, /bar/)", () => {181 shouldPass(() => assert.isRejected(promise, RangeError, /bar/));182 });183 describe(".isRejected(promise, RangeError, 'quux')", () => {184 shouldFail({185 op: () => assert.isRejected(promise, RangeError, "quux"),186 message: "to be rejected with an error including 'quux' but got 'foo bar'"187 });188 });189 describe(".isRejected(promise, RangeError, /quux/)", () => {190 shouldFail({191 op: () => assert.isRejected(promise, RangeError, /quux/),192 message: "to be rejected with an error matching /quux/ but got 'foo bar'"193 });194 });195 describe(".isRejected(promise, TypeError, 'foo')", () => {196 shouldFail({197 op: () => assert.isRejected(promise, TypeError, "foo"),198 message: "to be rejected with 'TypeError' but it was rejected with 'RangeError: foo bar'"199 });200 });201 describe(".isRejected(promise, TypeError, /bar/)", () => {202 shouldFail({203 op: () => assert.isRejected(promise, TypeError, /bar/),204 message: "to be rejected with 'TypeError' but it was rejected with 'RangeError: foo bar'"205 });206 });207 describe(".isRejected(promise, TypeError, 'quux')", () => {208 shouldFail({209 op: () => assert.isRejected(promise, TypeError, "quux"),210 message: "to be rejected with 'TypeError' but it was rejected with 'RangeError: foo bar'"211 });212 });213 describe(".isRejected(promise, TypeError, /quux/)", () => {214 shouldFail({215 op: () => assert.isRejected(promise, TypeError, /quux/),216 message: "to be rejected with 'TypeError' but it was rejected with 'RangeError: foo bar'"217 });218 });219 describe(".isRejected(promise, RangeError, 'foo', custom)", () => {220 shouldPass(() => assert.isRejected(promise, RangeError, "foo", custom));221 });222 describe(".isRejected(promise, RangeError, /bar/, custom)", () => {223 shouldPass(() => assert.isRejected(promise, RangeError, /bar/, custom));224 });225 describe(".isRejected(promise, RangeError, 'quux', custom)", () => {226 shouldFail({227 op: () => assert.isRejected(promise, RangeError, "quux", custom),228 message: custom229 });230 });231 describe(".isRejected(promise, RangeError, /quux/, custom)", () => {232 shouldFail({233 op: () => assert.isRejected(promise, RangeError, /quux/, custom),234 message: custom235 });236 });237 describe(".isRejected(promise, RangeError, undefined, custom)", () => {238 shouldPass(() => assert.isRejected(promise, RangeError, undefined, custom));239 });240 describe(".isRejected(promise, TypeError, undefined, custom)", () => {241 shouldFail({242 op: () => assert.isRejected(promise, TypeError, undefined, custom),243 message: custom244 });245 });246 });247 });...
preparedStatement.js
Source:preparedStatement.js
...66 it('setBigDecimal', async function() {67 await assert.isFulfilled(testPS.setBigDecimal(1, 1.0));68 });69 it('setBigDecimal should fail it passed bad params', async function() {70 await assert.isRejected(testPS.setBigDecimal());71 await assert.isRejected(testPS.setBigDecimal('bad-param', 1.0));72 await assert.isRejected(testPS.setBigDecimal(undefined, 1.0));73 await assert.isRejected(testPS.setBigDecimal(1, 'bad-param'));74 });75 it('setBoolean', async function() {76 await assert.isFulfilled(testPS.setBoolean(1, true));77 });78 it('setBoolean should fail it passed bad params', async function() {79 await assert.isRejected(testPS.setBoolean());80 await assert.isRejected(testPS.setBoolean('bad-param', 1.1));81 await assert.isRejected(testPS.setBoolean(undefined, 1.1));82 await assert.isRejected(testPS.setBoolean(1, 'bad-param'));83 });84 it('setByte', async function() {85 await assert.isFulfilled(testPS.setByte(1, 1));86 });87 it('setByte should fail it passed bad params', async function() {88 await assert.isRejected(testPS.setByte());89 await assert.isRejected(testPS.setByte('bad-param', 1.0));90 await assert.isRejected(testPS.setByte(undefined, 1.0));91 await assert.isRejected(testPS.setByte(1, 1.1));92 await assert.isRejected(testPS.setByte(1, 'bad-param'));93 });94 it('setBytes', async function() {95 await assert.isFulfilled(testPS.setBytes(1, [1,2,3]));96 });97 it('setBytes should fail it passed bad params', async function() {98 await assert.isRejected(testPS.setBytes());99 await assert.isRejected(testPS.setBytes('bad-param', 1.0));100 await assert.isRejected(testPS.setBytes(undefined, 1.0));101 await assert.isRejected(testPS.setBytes(1, 'bad-param'));102 await assert.isRejected(testPS.setBytes(1, ['bad-param']));103 });104 it('setDouble', async function() {105 await assert.isFulfilled(testPS.setDouble(1, 1.1));106 });107 it('setDouble should fail it passed bad params', async function() {108 await assert.isRejected(testPS.setDouble());109 await assert.isRejected(testPS.setDouble('bad-param', 1.1));110 await assert.isRejected(testPS.setDouble(undefined, 1.1));111 await assert.isRejected(testPS.setDouble(1, 'bad-param'));112 });113 it('setFloat', async function() {114 await assert.isFulfilled(testPS.setFloat(1, 1.0));115 });116 it('setFloat should fail it passed bad params', async function() {117 await assert.isRejected(testPS.setFloat());118 await assert.isRejected(testPS.setFloat('bad-param', 1.0));119 await assert.isRejected(testPS.setFloat(undefined, 1.0));120 await assert.isRejected(testPS.setFloat(1, 'bad-param'));121 });122 it('setInt', async function() {123 await assert.isFulfilled(testPS.setInt(1, 1));124 });125 it('setInt should fail it passed bad params', async function() {126 await assert.isRejected(testPS.setInt());127 await assert.isRejected(testPS.setInt('bad-param', 1.1));128 await assert.isRejected(testPS.setInt(undefined, 1.1));129 await assert.isRejected(testPS.setInt(1, 'bad-param'));130 });131 it('setLong', async function() {132 await assert.isFulfilled(testPS.setLong(1, 1));133 });134 it('setLong should fail it passed bad params', async function() {135 await assert.isRejected(testPS.setLong());136 await assert.isRejected(testPS.setLong('bad-param', 1.1));137 await assert.isRejected(testPS.setLong(undefined, 1.1));138 await assert.isRejected(testPS.setLong(1, 'bad-param'));139 });140 it('setString', async function() {141 await assert.isFulfilled(testPS.setString(1, 'fake-param'));142 });143 it('setString should fail it passed bad params', async function() {144 await assert.isRejected(testPS.setString());145 await assert.isRejected(testPS.setString('bad-param', ['bad-param']));146 await assert.isRejected(testPS.setString(undefined, 1));147 await assert.isRejected(testPS.setString(1, 1));148 });149 it('setDate', async function() {150 await assert.isFulfilled(testPS.setDate(1, '1970-01-01'));151 await assert.isFulfilled(testPS.setDate(1, '1970-01-01', 'fake-calendar'));152 });153 it('setDate should fail it passed bad params', async function() {154 await assert.isRejected(testPS.setDate());155 await assert.isRejected(testPS.setDate('bad-param', 1.0));156 await assert.isRejected(testPS.setDate(undefined, 1.0));157 await assert.isRejected(testPS.setDate(1, 1));158 await assert.isRejected(testPS.setDate(null, null, 1));159 });160 it('setTime', async function() {161 await assert.isFulfilled(testPS.setTime(1, '1970-01-01'));162 await assert.isFulfilled(testPS.setTime(1, '1970-01-01', 'fake-calendar'));163 });164 it('setTime should fail it passed bad params', async function() {165 await assert.isRejected(testPS.setTime());166 await assert.isRejected(testPS.setTime('bad-param', 1.0));167 await assert.isRejected(testPS.setTime(undefined, 1.0));168 await assert.isRejected(testPS.setTime(1, 1));169 await assert.isRejected(testPS.setTime(null, null, 1));170 });171 it('setTimestamp', async function() {172 await assert.isFulfilled(testPS.setTimestamp(1, 123));173 await assert.isFulfilled(testPS.setTimestamp(1, 123, 'fake-calendar'));174 });175 it('setTimestamp should fail it passed bad params', async function() {176 await assert.isRejected(testPS.setTimestamp());177 await assert.isRejected(testPS.setTimestamp('bad-param', 1.0));178 await assert.isRejected(testPS.setTimestamp(undefined, 1.0));179 await assert.isRejected(testPS.setTimestamp(1, 'bad-param'));180 await assert.isRejected(testPS.setTimestamp(null, null, 1));181 });...
Using AI Code Generation
1var promise = new Promise(function(resolve, reject) {2 setTimeout(function() {3 reject(new Error('REJECTED!'));4 }, 300);5});6function onReject(error) {7 console.log(error.message);8}9promise.then(null, onReject);10var promise = new Promise(function(resolve, reject) {11 setTimeout(function() {12 resolve('FULFILLED!');13 }, 300);14});15function onFulfilled(message) {16 console.log(message);17}18promise.then(onFulfilled);19var promise = new Promise(function(resolve, reject) {20 setTimeout(function() {21 resolve('FULFILLED!');22 }, 300);23});24function onFulfilled(message) {25 console.log(message);26}27promise.then(onFulfilled);28var promise = new Promise(function(resolve, reject) {29 setTimeout(function() {30 resolve('FULFILLED!');31 }, 300);32});33function onFulfilled(message) {34 console.log(message);35}36promise.then(onFulfilled);37var promise = new Promise(function(resolve, reject) {38 setTimeout(function() {39 reject(new Error('REJECTED!'));40 }, 300);41});42function onReject(error) {43 console.log(error.message);44}45promise.then(null, onReject);46var promise = new Promise(function(resolve, reject) {47 setTimeout(function() {48 resolve('I FIRED');49 reject(new Error('I DID NOT FIRE'));50 }, 300);51});52function onFulfilled(message) {53 console.log(message);54}55function onReject(error) {56 console.log(error.message);57}58promise.then(onFulfilled, onReject);59var promise = new Promise(function(resolve, reject) {60 resolve('PROMISE VALUE');61});62promise.then(console.log);63console.log('MAIN PROGRAM');64var promise = new Promise(function(resolve, reject) {65 resolve('PROMISE VALUE');66});
Using AI Code Generation
1var promise = new Promise(function (resolve, reject) {2 setTimeout(function () {3 reject(new Error("REJECTED!"));4 }, 300);5});6function onReject(error) {7 console.log(error.message);8}9promise.then(null, onReject);10var promise = new Promise(function (resolve, reject) {11 setTimeout(function () {12 reject(new Error("REJECTED!"));13 }, 300);14});15function onReject(error) {16 console.log(error.message);17}18promise.catch(onReject);19var promise = new Promise(function (resolve, reject) {20 setTimeout(function () {21 reject(new Error("REJECTED!"));22 }, 300);23});24function onReject(error) {25 console.log(error.message);26}27promise.catch(onReject);28var promise = new Promise(function (resolve, reject) {29 setTimeout(function () {30 reject(new Error("REJECTED!"));31 }, 300);32});33function onReject(error) {34 console.log(error.message);35}36promise.catch(onReject);37var promise = new Promise(function (resolve, reject) {38 setTimeout(function () {39 reject(new Error("REJECTED!"));40 }, 300);41});42function onReject(error) {43 console.log(error.message);44}45promise.catch(onReject);46var promise = new Promise(function (resolve, reject) {47 setTimeout(function () {48 reject(new Error("REJECTED!"));49 }, 300);50});51function onReject(error) {52 console.log(error.message);53}54promise.catch(onReject);55var promise = new Promise(function (resolve, reject) {56 setTimeout(function () {57 reject(new Error("REJECTED!"));58 }, 300);59});60function onReject(error) {61 console.log(error.message);62}63promise.catch(onReject);64var promise = new Promise(function (resolve, reject) {65 setTimeout(function () {66 reject(new Error("REJECTED!"));67 }, 300);68});69function onReject(error) {70 console.log(error.message);71}72promise.catch(onReject);73var promise = new Promise(function (resolve, reject) {74 setTimeout(function
Using AI Code Generation
1const promise = new Promise((resolve, reject) => {2 setTimeout(() => {3 resolve("Promise resolved");4 }, 1000);5});6setTimeout(() => {7}, 1500);8setTimeout(() => {9}, 2000);10setTimeout(() => {11}, 2500);12const promise = new Promise((resolve, reject) => {13 setTimeout(() => {14 resolve("Promise resolved");15 }, 1000);16});17const childPromise = promise.then((data) => {18 return new Promise((resolve, reject) => {19 setTimeout(() => {20 resolve(data + " and resolved again");21 }, 1000);22 });23});24setTimeout(() => {25}, 1500);26setTimeout(() => {27}, 2000);28setTimeout(() => {29}, 2500);30const promise = new Promise((resolve, reject) => {31 setTimeout(() => {32 reject("Promise rejected");33 }, 1000);34});35setTimeout(() => {36}, 1500);37setTimeout(() => {38}, 2000);39setTimeout(() => {40}, 2500);41const promise = new Promise((resolve, reject) => {42 setTimeout(() => {43 reject("Promise rejected");44 }, 1000);45});46const childPromise = promise.then((data) => {47 return new Promise((resolve, reject) => {48 setTimeout(() =>
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!