Best JavaScript code snippet using playwright-internal
Object.defineProperty.js
Source:Object.defineProperty.js
...7 describe('Object.defineProperty', function () {8 it('should throw a TypeError in each case', function () {9 expect(function () {10 utilx.Object.defineProperty();11 }).to.throwException(function (e) {12 expect(e).to.be.a(TypeError);13 });14 expect(function () {15 utilx.Object.defineProperty(undefined);16 }).to.throwException(function (e) {17 expect(e).to.be.a(TypeError);18 });19 expect(function () {20 utilx.Object.defineProperty(null);21 }).to.throwException(function (e) {22 expect(e).to.be.a(TypeError);23 });24 expect(function () {25 utilx.Object.defineProperty({}, 'foo');26 }).to.throwException(function (e) {27 expect(e).to.be.a(TypeError);28 });29 expect(function () {30 utilx.Object.defineProperty({}, 'foo', undefined);31 }).to.throwException(function (e) {32 expect(e).to.be.a(TypeError);33 });34 expect(function () {35 utilx.Object.defineProperty({}, 'foo', null);36 }).to.throwException(function (e) {37 expect(e).to.be.a(TypeError);38 });39 expect(function () {40 utilx.Object.defineProperty({}, 'foo', true);41 }).to.throwException(function (e) {42 expect(e).to.be.a(TypeError);43 });44 expect(function () {45 utilx.Object.defineProperty({}, 'foo', 1);46 }).to.throwException(function (e) {47 expect(e).to.be.a(TypeError);48 });49 });50 it('should not throw an error definining properties on plain objects', function () {51 expect(function () {52 var obj = utilx.Object.defineProperty({}, 'foo', {53 enumerable: true,54 writable: true,55 configurable: true56 });57 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();58 expect(obj.foo).to.be(undefined);59 }).to.not.throwException();60 expect(function () {61 var obj = utilx.Object.defineProperty({}, 'foo', {62 value: undefined,63 enumerable: true,64 writable: true,65 configurable: true66 });67 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();68 expect(obj.foo).to.be(undefined);69 }).to.not.throwException();70 expect(function () {71 var obj = utilx.Object.defineProperty({}, 'foo', {72 value: null,73 enumerable: true,74 writable: true,75 configurable: true76 });77 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();78 expect(obj.foo).to.be(null);79 }).to.not.throwException();80 expect(function () {81 var obj = utilx.Object.defineProperty({}, 'foo', {82 value: 1,83 enumerable: true,84 writable: true,85 configurable: true86 });87 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();88 expect(obj.foo).to.be(1);89 }).to.not.throwException();90 expect(function () {91 var obj = utilx.Object.defineProperty({}, 'foo', {92 value: true,93 enumerable: true,94 writable: true,95 configurable: true96 });97 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();98 expect(obj.foo).to.be(true);99 }).to.not.throwException();100 expect(function () {101 var obj = utilx.Object.defineProperty({}, 'foo', {102 value: '',103 enumerable: true,104 writable: true,105 configurable: true106 });107 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();108 expect(obj.foo).to.be('');109 }).to.not.throwException();110 expect(function () {111 var obj = utilx.Object.defineProperty({}, 'foo', {112 value: {},113 enumerable: true,114 writable: true,115 configurable: true116 });117 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();118 expect(obj.foo).to.eql({});119 }).to.not.throwException();120 expect(function () {121 var obj = utilx.Object.defineProperty({}, 'foo', {122 value: [],123 enumerable: true,124 writable: true,125 configurable: true126 });127 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();128 expect(obj.foo).to.eql([]);129 }).to.not.throwException();130 expect(function () {131 var obj = utilx.Object.defineProperty({}, 'foo', {132 value: required.noop,133 enumerable: true,134 writable: true,135 configurable: true136 });137 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();138 expect(obj.foo).to.be(required.noop);139 }).to.not.throwException();140 });141 it('should not throw an error redefinining properties on plain objects', function () {142 expect(function () {143 var obj = {144 foo: 10145 };146 utilx.Object.defineProperty(obj, 'foo', {147 enumerable: true,148 writable: true,149 configurable: true150 });151 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();152 expect(obj.foo).to.be(10);153 utilx.Object.defineProperty(obj, 'foo', {154 enumerable: false,155 writable: false,156 configurable: false157 });158 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();159 expect(obj.foo).to.be(10);160 }).to.not.throwException();161 });162 it('should not throw an error redefinining elements on arrays', function () {163 expect(function () {164 var obj = utilx.Object.defineProperty([10], '0', {165 enumerable: true,166 writable: true,167 configurable: true168 });169 expect(obj.length).to.be(1);170 expect(obj[0]).to.be(10);171 }).to.not.throwException();172 });173 it('should not throw an error definining properties on arrays', function () {174 expect(function () {175 var obj = utilx.Object.defineProperty([], 'foo', {176 enumerable: true,177 writable: true,178 configurable: true179 });180 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();181 expect(obj.foo).to.be(undefined);182 }).to.not.throwException();183 expect(function () {184 var obj = utilx.Object.defineProperty([], 'foo', {185 value: undefined,186 enumerable: true,187 writable: true,188 configurable: true189 });190 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();191 expect(obj.foo).to.be(undefined);192 }).to.not.throwException();193 expect(function () {194 var obj = utilx.Object.defineProperty([], 'foo', {195 value: null,196 enumerable: true,197 writable: true,198 configurable: true199 });200 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();201 expect(obj.foo).to.be(null);202 }).to.not.throwException();203 expect(function () {204 var obj = utilx.Object.defineProperty([], 'foo', {205 value: 1,206 enumerable: true,207 writable: true,208 configurable: true209 });210 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();211 expect(obj.foo).to.be(1);212 }).to.not.throwException();213 expect(function () {214 var obj = utilx.Object.defineProperty([], 'foo', {215 value: true,216 enumerable: true,217 writable: true,218 configurable: true219 });220 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();221 expect(obj.foo).to.be(true);222 }).to.not.throwException();223 expect(function () {224 var obj = utilx.Object.defineProperty([], 'foo', {225 value: '',226 enumerable: true,227 writable: true,228 configurable: true229 });230 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();231 expect(obj.foo).to.be('');232 }).to.not.throwException();233 expect(function () {234 var obj = utilx.Object.defineProperty([], 'foo', {235 value: required.noop,236 enumerable: true,237 writable: true,238 configurable: true239 });240 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();241 expect(obj.foo).to.be(required.noop);242 }).to.not.throwException();243 });244 it('should not throw an error definining elements on arrays using integer strings', function () {245 expect(function () {246 var obj = utilx.Object.defineProperty([], '0', {247 enumerable: true,248 writable: true,249 configurable: true250 });251 expect(obj.length).to.be(1);252 expect(obj[0]).to.be(undefined);253 }).to.not.throwException();254 expect(function () {255 var obj = utilx.Object.defineProperty([], '0', {256 value: undefined,257 enumerable: true,258 writable: true,259 configurable: true260 });261 expect(obj.length).to.be(1);262 expect(obj[0]).to.be(undefined);263 }).to.not.throwException();264 expect(function () {265 var obj = utilx.Object.defineProperty([], '0', {266 value: null,267 enumerable: true,268 writable: true,269 configurable: true270 });271 expect(utilx.Object.hasOwn(obj, '0')).to.be.ok();272 expect(obj.length).to.be(1);273 expect(obj[0]).to.be(null);274 }).to.not.throwException();275 expect(function () {276 var obj = utilx.Object.defineProperty([], '0', {277 enumerable: true,278 writable: true,279 configurable: true280 });281 expect(obj.length).to.be(1);282 expect(obj[0]).to.be(undefined);283 }).to.not.throwException();284 expect(function () {285 var obj = utilx.Object.defineProperty([], '0', {286 value: undefined,287 enumerable: true,288 writable: true,289 configurable: true290 });291 expect(obj.length).to.be(1);292 expect(obj[0]).to.be(undefined);293 }).to.not.throwException();294 expect(function () {295 var obj = utilx.Object.defineProperty([], '0', {296 value: null,297 enumerable: true,298 writable: true,299 configurable: true300 });301 expect(utilx.Object.hasOwn(obj, '0')).to.be.ok();302 expect(obj.length).to.be(1);303 expect(obj[0]).to.be(null);304 }).to.not.throwException();305 });306 it('should not throw an error definining elements on arrays using integer numbers', function () {307 expect(function () {308 var obj = utilx.Object.defineProperty([], 0, {309 enumerable: true,310 writable: true,311 configurable: true312 });313 expect(obj.length).to.be(1);314 expect(obj[0]).to.be(undefined);315 }).to.not.throwException();316 expect(function () {317 var obj = utilx.Object.defineProperty([], 0, {318 value: undefined,319 enumerable: true,320 writable: true,321 configurable: true322 });323 expect(obj.length).to.be(1);324 expect(obj[0]).to.be(undefined);325 }).to.not.throwException();326 expect(function () {327 var obj = utilx.Object.defineProperty([], 0, {328 value: null,329 enumerable: true,330 writable: true,331 configurable: true332 });333 expect(utilx.Object.hasOwn(obj, 0)).to.be.ok();334 expect(obj.length).to.be(1);335 expect(obj[0]).to.be(null);336 }).to.not.throwException();337 expect(function () {338 var obj = utilx.Object.defineProperty([], 1, {339 enumerable: true,340 writable: true,341 configurable: true342 });343 expect(obj.length).to.be(2);344 expect(obj[1]).to.be(undefined);345 }).to.not.throwException();346 expect(function () {347 var obj = utilx.Object.defineProperty([], 1, {348 value: undefined,349 enumerable: true,350 writable: true,351 configurable: true352 });353 expect(obj.length).to.be(2);354 expect(obj[1]).to.be(undefined);355 }).to.not.throwException();356 expect(function () {357 var obj = utilx.Object.defineProperty([], 1, {358 value: null,359 enumerable: true,360 writable: true,361 configurable: true362 });363 expect(utilx.Object.hasOwn(obj, 1)).to.be.ok();364 expect(obj.length).to.be(2);365 expect(obj[1]).to.be(null);366 }).to.not.throwException();367 });368 it('should not throw an error definining elements on arrays using float numbers', function () {369 expect(function () {370 var obj = utilx.Object.defineProperty([], 1.1, {371 enumerable: true,372 writable: true,373 configurable: true374 });375 expect(utilx.Object.hasOwn(obj, 1.1)).to.be.ok();376 expect(obj.length).to.be(0);377 expect(obj[1.1]).to.be(undefined);378 }).to.not.throwException();379 expect(function () {380 var obj = utilx.Object.defineProperty([], 1.1, {381 value: undefined,382 enumerable: true,383 writable: true,384 configurable: true385 });386 expect(utilx.Object.hasOwn(obj, 1.1)).to.be.ok();387 expect(obj.length).to.be(0);388 expect(obj[1.1]).to.be(undefined);389 }).to.not.throwException();390 expect(function () {391 var obj = utilx.Object.defineProperty([], 1.1, {392 value: null,393 enumerable: true,394 writable: true,395 configurable: true396 });397 expect(utilx.Object.hasOwn(obj, 1.1)).to.be.ok();398 expect(obj.length).to.be(0);399 expect(obj[1.1]).to.be(null);400 }).to.not.throwException();401 });402 it('should not throw an error definining elements on arrays using trailing point numbers', function () {403 /*jshint -W047 */404 expect(function () {405 var obj = utilx.Object.defineProperty([], 1., {406 enumerable: true,407 writable: true,408 configurable: true409 });410 expect(obj.length).to.be(2);411 expect(obj[1]).to.be(undefined);412 }).to.not.throwException();413 expect(function () {414 var obj = utilx.Object.defineProperty([], 1., {415 value: undefined,416 enumerable: true,417 writable: true,418 configurable: true419 });420 expect(obj.length).to.be(2);421 expect(obj[1]).to.be(undefined);422 }).to.not.throwException();423 expect(function () {424 var obj = utilx.Object.defineProperty([], 1., {425 value: null,426 enumerable: true,427 writable: true,428 configurable: true429 });430 expect(obj.length).to.be(2);431 expect(obj[1]).to.be(null);432 }).to.not.throwException();433 });434 it('should not throw an error definining elements on arrays using trailing point numbers strings', function () {435 expect(function () {436 var obj = utilx.Object.defineProperty([], '1.', {437 enumerable: true,438 writable: true,439 configurable: true440 });441 expect(obj.length).to.be(0);442 expect(obj['1.']).to.be(undefined);443 }).to.not.throwException();444 expect(function () {445 var obj = utilx.Object.defineProperty([], '1.', {446 value: undefined,447 enumerable: true,448 writable: true,449 configurable: true450 });451 expect(obj.length).to.be(0);452 expect(obj['1.']).to.be(undefined);453 }).to.not.throwException();454 expect(function () {455 var obj = utilx.Object.defineProperty([], '1.', {456 value: null,457 enumerable: true,458 writable: true,459 configurable: true460 });461 expect(obj.length).to.be(0);462 expect(obj['1.']).to.be(null);463 }).to.not.throwException();464 expect(function () {465 var obj = utilx.Object.defineProperty([], '1.', {466 value: true,467 enumerable: true,468 writable: true,469 configurable: true470 });471 expect(obj.length).to.be(0);472 expect(obj['1.']).to.be(true);473 }).to.not.throwException();474 /*jshint +W047 */475 });476 it('should not throw an error definining properties on functions', function () {477 expect(function () {478 var obj = utilx.Object.defineProperty(function () { return; }, 'foo', {479 enumerable: true,480 writable: true,481 configurable: true482 });483 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();484 expect(obj.foo).to.be(undefined);485 }).to.not.throwException();486 expect(function () {487 var obj = utilx.Object.defineProperty(function () { return; }, 'foo', {488 value: undefined,489 enumerable: true,490 writable: true,491 configurable: true492 });493 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();494 expect(obj.foo).to.be(undefined);495 }).to.not.throwException();496 expect(function () {497 var obj = utilx.Object.defineProperty(function () { return; }, 'foo', {498 value: null,499 enumerable: true,500 writable: true,501 configurable: true502 });503 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();504 expect(obj.foo).to.be(null);505 }).to.not.throwException();506 expect(function () {507 var obj = utilx.Object.defineProperty(function () { return; }, 'foo', {508 value: {},509 enumerable: true,510 writable: true,511 configurable: true512 });513 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();514 expect(obj.foo).to.eql({});515 }).to.not.throwException();516 expect(function () {517 var obj = utilx.Object.defineProperty(function () { return; }, 'foo', {518 value: [],519 enumerable: true,520 writable: true,521 configurable: true522 });523 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();524 expect(obj.foo).to.eql([]);525 }).to.not.throwException();526 expect(function () {527 var obj = utilx.Object.defineProperty(function () { return; }, 'foo', {528 value: '',529 enumerable: true,530 writable: true,531 configurable: true532 });533 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();534 expect(obj.foo).to.be('');535 }).to.not.throwException();536 expect(function () {537 var obj = utilx.Object.defineProperty(function () { return; }, 'foo', {538 value: true,539 enumerable: true,540 writable: true,541 configurable: true542 });543 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();544 expect(obj.foo).to.be(true);545 }).to.not.throwException();546 expect(function () {547 var obj = utilx.Object.defineProperty(function () { return; }, 'foo', {548 value: 1,549 enumerable: true,550 writable: true,551 configurable: true552 });553 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();554 expect(obj.foo).to.be(1);555 }).to.not.throwException();556 expect(function () {557 var obj = utilx.Object.defineProperty(function () { return; }, 'foo', {558 value: required.noop,559 enumerable: true,560 writable: true,561 configurable: true562 });563 expect(utilx.Object.hasOwn(obj, 'foo')).to.be.ok();564 expect(obj.foo).to.be(required.noop);565 }).to.not.throwException();566 });567 });...
Object.keys.js
Source:Object.keys.js
...68 /*jshint +W001 */69 it('should throw if no arguments', function () {70 expect(function () {71 reiterate.$.keys();72 }).to.throwException(function (e) {73 expect(e).to.be.a(TypeError);74 });75 });76 it('should throw if argument is undefined', function () {77 expect(function () {78 reiterate.$.keys(undefined);79 }).to.throwException(function (e) {80 expect(e).to.be.a(TypeError);81 });82 });83 it('should throw if argument is null', function () {84 expect(function () {85 reiterate.$.keys(null);86 }).to.throwException(function (e) {87 expect(e).to.be.a(TypeError);88 });89 });90 it('should not throw an TypeError if argument is primitive', function () {91 var primKeys;92 expect(function () {93 primKeys = reiterate.$.keys(42);94 }).to.not.throwException();95 expect(primKeys.length).to.be(0);96 expect(function () {97 primKeys = reiterate.$.keys(true);98 }).to.not.throwException();99 expect(primKeys.length).to.be(0);100 expect(function () {101 primKeys = reiterate.$.keys('abc');102 }).to.not.throwException();103 expect(primKeys.length).to.be(3);104 });105 it('should not throw an error in each case', function () {106 expect(keys.length).to.be(14);107 expect(reiterate.$.isArray(keys)).to.be.ok();108 reiterate.$.forEach(keys, function (name) {109 expect(Object.prototype.hasOwnProperty.call(obj, name)).to.be.ok();110 });111 reiterate.$.forEach(keys, function (name) {112 // should return names which are enumerable113 expect(reiterate.$.indexOf(loopedValues, name)).not.to.be(-1);114 });115 expect(keys2.length).to.be(7);116 expect(reiterate.$.isArray(keys2)).to.be.ok();117 reiterate.$.forEach(keys2, function (name) {118 expect(Object.prototype.hasOwnProperty.call(obj, name)).to.be.ok();119 });120 reiterate.$.forEach(keys2, function (name) {121 // should return names which are enumerable122 expect(reiterate.$.indexOf(loopedValues2, name)).not.to.be(-1);123 });124 });125 it('should work with arguments object', function () {126 var testValue = [0, 1],127 theArgs = reiterate.$.returnArgs(1, 2),128 theKeys;129 expect(function () {130 theKeys = reiterate.$.keys(theArgs);131 }).to.not.throwException();132 expect(theKeys.length).to.be(2);133 expect(theKeys).to.eql(testValue);134 });135 it('should work with string object', function () {136 var testValue = ['0', '1', '2'],137 theObj = Object('hej'),138 theKeys;139 expect(function () {140 theKeys = reiterate.$.keys(theObj);141 }).to.not.throwException();142 expect(theKeys).to.eql(testValue);143 expect(theKeys.length).to.be(3);144 });145 it('Constructor should not list prototype or constructor', function () {146 var pKeys;147 function Constructor() {148 this.constructor = this.prototype = 1;149 }150 Constructor.prototype.constructor = 1;151 expect(function () {152 pKeys = reiterate.$.keys(Constructor);153 }).to.not.throwException();154 expect(pKeys).to.eql([]);155 });156 it('Constructor prototype should not list constructor', function () {157 var pKeys;158 function Constructor() {159 this.constructor = this.prototype = 1;160 }161 Constructor.prototype.constructor = 1;162 expect(function () {163 pKeys = reiterate.$.keys(Constructor.prototype);164 }).to.not.throwException();165 expect(pKeys).to.eql([]);166 });167 it('should list prototype and constructor', function () {168 var pKeys;169 function Constructor() {170 this.constructor = this.prototype = 1;171 }172 Constructor.prototype.constructor = 1;173 expect(function () {174 pKeys = reiterate.$.keys(new Constructor());175 }).to.not.throwException();176 expect(pKeys.sort()).to.eql(['constructor', 'prototype']);177 });178 it('Object prototype should not list', function () {179 var pKeys;180 expect(function () {181 pKeys = reiterate.$.keys(Object.prototype);182 }).to.not.throwException(function (e) {183 expect(e).to.be(undefined);184 });185 expect(pKeys).to.eql([]);186 });187 it('Function prototype should not list', function () {188 var pKeys;189 expect(function () {190 pKeys = reiterate.$.keys(Function.prototype);191 }).to.not.throwException(function (e) {192 expect(e).to.be(undefined);193 });194 expect(pKeys).to.eql([]);195 });196 it('Boolean prototype should not list', function () {197 var pKeys;198 expect(function () {199 pKeys = reiterate.$.keys(Boolean.prototype);200 }).to.not.throwException(function (e) {201 expect(e).to.be(undefined);202 });203 expect(pKeys).to.eql([]);204 });205 it('String prototype should not list', function () {206 var pKeys;207 expect(function () {208 pKeys = reiterate.$.keys(String.prototype);209 }).to.not.throwException();210 expect(pKeys).to.eql([]);211 });212 it('Number prototype should not list', function () {213 var pKeys;214 expect(function () {215 pKeys = reiterate.$.keys(Number.prototype);216 }).to.not.throwException();217 expect(pKeys).to.eql([]);218 });219 it('Error prototype should not list', function () {220 var pKeys;221 expect(function () {222 pKeys = reiterate.$.keys(Error.prototype);223 }).to.not.throwException();224 expect(pKeys).to.eql([]);225 });226 it('TypeError prototype should not list', function () {227 var pKeys;228 expect(function () {229 pKeys = reiterate.$.keys(TypeError.prototype);230 }).to.not.throwException();231 expect(pKeys).to.eql([]);232 });233 it('SyntaxError prototype should not list', function () {234 var pKeys;235 expect(function () {236 pKeys = reiterate.$.keys(SyntaxError.prototype);237 }).to.not.throwException();238 expect(pKeys).to.eql([]);239 });240 it('RangeError prototype should not list', function () {241 var pKeys;242 expect(function () {243 pKeys = reiterate.$.keys(RangeError.prototype);244 }).to.not.throwException();245 expect(pKeys).to.eql([]);246 });247 it('EvalError prototype should not list', function () {248 var pKeys;249 expect(function () {250 pKeys = reiterate.$.keys(EvalError.prototype);251 }).to.not.throwException();252 expect(pKeys).to.eql([]);253 });254 it('URIError prototype should not list', function () {255 var pKeys;256 expect(function () {257 pKeys = reiterate.$.keys(URIError.prototype);258 }).to.not.throwException();259 expect(pKeys).to.eql([]);260 });261 it('ReferenceError prototypes should not list', function () {262 var pKeys;263 expect(function () {264 pKeys = reiterate.$.keys(ReferenceError.prototype);265 }).to.not.throwException();266 expect(pKeys).to.eql([]);267 });268 it('Date prototype should not list', function () {269 var pKeys;270 expect(function () {271 pKeys = reiterate.$.keys(Date.prototype);272 }).to.not.throwException();273 expect(pKeys).to.eql([]);274 });275 it('RegExp prototype should not list', function () {276 var pKeys;277 expect(function () {278 pKeys = reiterate.$.keys(RegExp.prototype);279 }).to.not.throwException();280 expect(pKeys).to.eql([]);281 });282 it('should not enumerate over non-enumerable properties', function () {283 var Foo = function () {284 return;285 },286 pKeys;287 expect(function () {288 pKeys = reiterate.$.keys(Foo.prototype);289 }).to.not.throwException();290 expect(pKeys).to.eql([]);291 });292 });...
Assert.js
Source:Assert.js
...12 }1314 function isArray (obj, message, exception) {15 if (!Type.isArray(obj)) {16 throwException(exception, message)17 }18 }1920 function isBoolean (obj, message, exception) {21 if (!Type.isBoolean(obj)) {22 throwException(exception, message)23 }24 }2526 function isDate (obj, message, exception) {27 if (!Type.isDate(obj)) {28 throwException(exception, message)29 }30 }3132 function isFunction (obj, message, exception) {33 if (!Type.isFunction(obj)) {34 throwException(exception, message)35 }36 }3738 function isNull (obj, message, exception) {39 if (!Type.isNull(obj)) {40 throwException(exception, message)41 }42 }4344 function isNumber (obj, message, exception) {45 if (!Type.isNumber(obj)) {46 throwException(exception, message)47 }48 }4950 function isObject (obj, message, exception) {51 if (!Type.isObject(obj)) {52 throwException(exception, message)53 }54 }5556 function isRegExp (obj, message, exception) {57 if (!Type.isRegExp(obj)) {58 throwException(exception, message)59 }60 }6162 function isString (obj, message, exception) {63 if (!Type.isString(obj)) {64 throwException(exception, message)65 }66 }6768 function isUndefined (obj, message, exception) {69 if (!Type.isUndefined(obj)) {70 throwException(exception, message)71 }72 }7374 function isNotArray (obj, message, exception) {75 if (Type.isArray(obj)) {76 throwException(exception, message)77 }78 }7980 function isNotBoolean (obj, message, exception) {81 if (Type.isBoolean(obj)) {82 throwException(exception, message)83 }84 }8586 function isNotDate (obj, message, exception) {87 if (Type.isDate(obj)) {88 throwException(exception, message)89 }90 }9192 function isNotFunction (obj, message, exception) {93 if (Type.isFunction(obj)) {94 throwException(exception, message)95 }96 }9798 function isNotNull (obj, message, exception) {99 if (Type.isNull(obj)) {100 throwException(exception, message)101 }102 }103104 function isNotNumber (obj, message, exception) {105 if (Type.isNumber(obj)) {106 throwException(exception, message)107 }108 }109110 function isNotObject (obj, message, exception) {111 if (Type.isObject(obj)) {112 throwException(exception, message)113 }114 }115116 function isNotRegExp (obj, message, exception) {117 if (Type.isRegExp(obj)) {118 throwException(exception, message)119 }120 }121122 function isNotString (obj, message, exception) {123 if (Type.isString(obj)) {124 throwException(exception, message)125 }126 }127128 function isNotUndefined (obj, message, exception) {129 if (Type.isUndefined(obj)) {130 throwException(exception, message)131 }132 }133134 function ensureIndex (min, max, index, message, exception) {135 if (Type.isNullOrUndefined(index) || index < min || index > max) {136 throwException(137 Dolphin.IndexException || exception,138 message || 'ç´¢å¼ ' + index + ' è¶
åºç¯å ' + min + ',' + max)139 }140 }141142 function isTrue (condition, message, exception) {143 if (!condition) {144 throwException(exception, message || 'æ¢ä»¶å¿
é æ¯ True')145 }146 }147148 function isInstanceOf (child, parent, message, exception) {149 if (!(child instanceof parent)) {150 throwException(151 exception,152 message || Type.getType(child) + ' å¿
é æ¯ ' + Type.getType(parent) +153 ' ç實ä¾')154 }155 }156157 function isNotEmptyString (obj, message, exception) {158 if (!Type.isString(obj)) {159 throwException(exception, 'ç©ä»¶ä¸æ¯å串')160 }161162 if (obj.length === 0) {163 throwException(exception, message || 'å串å¿
é æå¼')164 }165 }166167 function isEmptyString (obj, message, exception) {168 if (Type.isNotString(obj)) {169 throwException(exception, 'ç©ä»¶ä¸æ¯å串')170 }171172 if (obj.length !== 0) {173 throwException(exception, message || 'å串å¿
é ç¡å¼')174 }175 }176177 function isEqual (obj, other, message, exception) {178 if (!Type.deepEqual(obj, other)) {179 throwException(exception, message || 'åæ¸ obj è other å¿
é ç¸å')180 }181 }182183 function isNotEqual (obj, other, message, exception) {184 if (Type.deepEqual(obj, other)) {185 throwException(exception, message || 'åæ¸ obj è other å¿
é ä¸ç¸å')186 }187 }188189 function hasKey (obj, key, message, exception) {190 if (!obj.hasOwnProperty(key)) {191 throwException(exception, message || 'ç©ä»¶æ²æéµå¼ ' + key)192 }193 }194195 function isNullOrUndefined (obj, message, exception) {196 if (Type.isNotNullOrUndefined(obj)) {197 throwException(exception, message)198 }199 }200201 function isNotNullOrUndefined (obj, message, exception) {202 if (Type.isNullOrUndefined(obj)) {203 throwException(exception || Dolphin.NullException, message)204 }205 }206207 // ---- export ------------------------------------------208 return {209 hasKey: hasKey,210 ensureIndex: ensureIndex,211 isArray: isArray,212 isBoolean: isBoolean,213 isDate: isDate,214 isEmptyString: isEmptyString,215 isEqual: isEqual,216 isFunction: isFunction,217 isInstanceOf: isInstanceOf,
...
_fail_fast_test.js
Source:_fail_fast_test.js
...16});17describe("FailFast", function() {18 it("checks if variable is defined", function() {19 var unlessDefined = wrap(failFast.unlessDefined);20 expect(unlessDefined("foo")).to.not.throwException();21 expect(unlessDefined(null)).to.not.throwException();22 expect(unlessDefined(undefined)).to.throwException(/Required variable was not defined/);23 expect(unlessDefined(undefined, "myVariable")).to.throwException(/Required variable \[myVariable\] was not defined/);24 });25 it("checks if variable is number, string, or array", function() {26 var unlessNumber = wrap(failFast.unlessNumber);27 var unlessString = wrap(failFast.unlessString);28 var unlessArray = wrap(failFast.unlessArray);29 var unlessFunction = wrap(failFast.unlessFunction);30 expect(unlessNumber(0)).to.not.throwException();31 expect(unlessNumber("foo")).to.throwException(/Expected variable to be number, but was string/);32 expect(unlessNumber({})).to.throwException(/Expected variable to be number, but was object/);33 expect(unlessNumber([])).to.throwException(/Expected variable to be number, but was array/);34 expect(unlessNumber(undefined)).to.throwException(/Expected variable to be number, but was undefined/);35 expect(unlessNumber(null)).to.throwException(/Expected variable to be number, but was null/);36 expect(unlessNumber(NaN)).to.throwException(/Expected variable to be number, but was NaN/);37 expect(unlessNumber("foo", "name")).to.throwException(/Expected variable \[name\] to be number, but was string/);38 expect(unlessString(null, "name")).to.throwException(/Expected variable \[name\] to be string, but was null/);39 expect(unlessArray(null, "name")).to.throwException(/Expected variable \[name\] to be array, but was null/);40 expect(unlessFunction(null, "name")).to.throwException(/Expected variable \[name\] to be function, but was null/);41 });42 it("checks if variable is object of specific type", function() {43 function Example1() {}44 function Example2() {}45 function NoConstructor() {}46 delete NoConstructor.constructor;47 var Anon = function() {};48 var unlessObject = wrap(failFast.unlessObject);49 expect(unlessObject(new Example1())).to.not.throwException();50 expect(unlessObject(new Example1(), Example1)).to.not.throwException();51 expect(unlessObject(null, Example1)).to.throwException(/Expected variable to be object, but was null/);52 expect(unlessObject(new Example1(), Example2)).to.throwException(/Expected object to be (Example2 instance|a specific type)(, but was Example1)?/);53 expect(unlessObject(new Anon(), Example2)).to.throwException(/Expected object to be (Example2 instance|a specific type)/);54 expect(unlessObject(new NoConstructor(), Example2)).to.throwException(/Expected object to be (Example2 instance|a specific type)/);55 expect(unlessObject(new Example1(), Example2, "name")).to.throwException(/Expected object \[name\] to be (Example2 instance|a specific type)/);56 if (Object.create) { // don't run this test on IE 857 expect(unlessObject(Object.create(null), Example2)).to.throwException(/Expected object to be (Example2 instance|a specific type), but it has no prototype/);58 }59 });60 it("checks if condition is true", function() {61 var unlessTrue = wrap(failFast.unlessTrue);62 expect(unlessTrue(true)).to.not.throwException();63 expect(unlessTrue(false)).to.throwException(/Expected condition to be true/);64 expect(unlessTrue(false, "a message")).to.throwException(/a message/);65 expect(unlessTrue("foo")).to.throwException(/Expected condition to be true or false/);66 expect(unlessTrue("foo", "ignored")).to.throwException(/Expected condition to be true or false/);67 });68 it("fails when unreachable code is executed", function() {69 var unreachable = wrap(failFast.unreachable);70 expect(unreachable()).to.throwException(/Unreachable code executed/);71 expect(unreachable("foo")).to.throwException(/foo/);72 });73 function wrap(fn) {74 return function() {75 var outerArgs = arguments;76 return function() {77 fn.apply(this, outerArgs);78 };79 };80 }...
Object.isEmpty.js
Source:Object.isEmpty.js
...15 describe('Object.isEmpty', function () {16 it('should throw a TypeError in each case', function () {17 expect(function () {18 utilx.Object.isEmpty();19 }).to.throwException(function (e) {20 expect(e).to.be.a(TypeError);21 });22 expect(function () {23 utilx.Object.isEmpty(undefined);24 }).to.throwException(function (e) {25 expect(e).to.be.a(TypeError);26 });27 expect(function () {28 utilx.Object.isEmpty(null);29 }).to.throwException(function (e) {30 expect(e).to.be.a(TypeError);31 });32 expect(function () {33 utilx.Object.isEmpty('');34 }).to.throwException(function (e) {35 expect(e).to.be.a(TypeError);36 });37 expect(function () {38 utilx.Object.isEmpty(1);39 }).to.throwException(function (e) {40 expect(e).to.be.a(TypeError);41 });42 expect(function () {43 utilx.Object.isEmpty(true);44 }).to.throwException(function (e) {45 expect(e).to.be.a(TypeError);46 });47 });48 it('should true in each case', function () {49 expect(function () {50 utilx.Object.isEmpty({});51 }).to.not.throwException();52 expect(utilx.Object.isEmpty({})).to.be(true);53 expect(function () {54 utilx.Object.isEmpty([]);55 }).to.not.throwException();56 expect(utilx.Object.isEmpty([])).to.be(true);57 expect(function () {58 utilx.Object.isEmpty(required.noop);59 }).to.not.throwException();60 expect(utilx.Object.isEmpty(required.noop)).to.be(true);61 expect(function () {62 utilx.Object.isEmpty(X);63 }).to.not.throwException();64 expect(utilx.Object.isEmpty(X)).to.be(true);65 });66 it('should false in each case', function () {67 expect(function () {68 utilx.Object.isEmpty({toString: required.noop});69 }).to.not.throwException();70 expect(utilx.Object.isEmpty({toString: required.noop})).to.be(false);71 expect(function () {72 utilx.Object.isEmpty({valueOf: required.noop});73 }).to.not.throwException();74 expect(utilx.Object.isEmpty({valueOf: required.noop})).to.be(false);75 expect(function () {76 utilx.Object.isEmpty([1]);77 }).to.not.throwException();78 expect(utilx.Object.isEmpty([1])).to.be(false);79 expect(function () {80 utilx.Object.isEmpty(X.prototype);81 }).to.not.throwException();82 expect(utilx.Object.isEmpty(X.prototype)).to.be(false);83 expect(function () {84 utilx.Object.isEmpty(X.prototype);85 }).to.not.throwException();86 expect(utilx.Object.isEmpty(X.prototype)).to.be(false);87 });88 });...
Object.RequireObjectCoercible.js
Source:Object.RequireObjectCoercible.js
...14 describe('Object.reiterate.$.requireObjectCoercible', function () {15 it('should not throw an error in each case', function () {16 expect(function () {17 reiterate.$.requireObjectCoercible();18 }).to.throwException(function (e) {19 expect(e).to.be.a(TypeError);20 });21 expect(function () {22 reiterate.$.requireObjectCoercible(undefined);23 }).to.throwException(function (e) {24 expect(e).to.be.a(TypeError);25 });26 expect(function () {27 reiterate.$.requireObjectCoercible(null);28 }).to.throwException(function (e) {29 expect(e).to.be.a(TypeError);30 });31 expect(function () {32 reiterate.$.requireObjectCoercible(-1);33 }).to.not.throwException();34 expect(function () {35 reiterate.$.requireObjectCoercible(0);36 }).to.not.throwException();37 expect(function () {38 reiterate.$.requireObjectCoercible(1);39 }).to.not.throwException();40 expect(function () {41 reiterate.$.requireObjectCoercible(NaN);42 }).to.not.throwException();43 expect(function () {44 reiterate.$.requireObjectCoercible(Infinity);45 }).to.not.throwException();46 expect(function () {47 reiterate.$.requireObjectCoercible(-Infinity);48 }).to.not.throwException();49 expect(function () {50 reiterate.$.requireObjectCoercible(true);51 }).to.not.throwException();52 expect(function () {53 reiterate.$.requireObjectCoercible(false);54 }).to.not.throwException();55 expect(function () {56 reiterate.$.requireObjectCoercible('');57 }).to.not.throwException();58 expect(function () {59 reiterate.$.requireObjectCoercible('x');60 }).to.not.throwException();61 expect(function () {62 reiterate.$.requireObjectCoercible(reiterate.$.noop);63 }).to.not.throwException();64 expect(function () {65 reiterate.$.requireObjectCoercible(new RegExp('y'));66 }).to.not.throwException();67 expect(function () {68 reiterate.$.requireObjectCoercible(new Date());69 }).to.not.throwException();70 });71 });...
Object.CheckObjectCoercible.js
Source:Object.CheckObjectCoercible.js
...7 describe('Object.CheckObjectCoercible', function () {8 it('should not throw an error in each case', function () {9 expect(function () {10 utilx.Object.CheckObjectCoercible();11 }).to.throwException(function (e) {12 expect(e).to.be.a(TypeError);13 });14 expect(function () {15 utilx.Object.CheckObjectCoercible(undefined);16 }).to.throwException(function (e) {17 expect(e).to.be.a(TypeError);18 });19 expect(function () {20 utilx.Object.CheckObjectCoercible(null);21 }).to.throwException(function (e) {22 expect(e).to.be.a(TypeError);23 });24 expect(function () {25 utilx.Object.CheckObjectCoercible(-1);26 }).to.not.throwException();27 expect(function () {28 utilx.Object.CheckObjectCoercible(0);29 }).to.not.throwException();30 expect(function () {31 utilx.Object.CheckObjectCoercible(1);32 }).to.not.throwException();33 expect(function () {34 utilx.Object.CheckObjectCoercible(NaN);35 }).to.not.throwException();36 expect(function () {37 utilx.Object.CheckObjectCoercible(Infinity);38 }).to.not.throwException();39 expect(function () {40 utilx.Object.CheckObjectCoercible(-Infinity);41 }).to.not.throwException();42 expect(function () {43 utilx.Object.CheckObjectCoercible(true);44 }).to.not.throwException();45 expect(function () {46 utilx.Object.CheckObjectCoercible(false);47 }).to.not.throwException();48 expect(function () {49 utilx.Object.CheckObjectCoercible('');50 }).to.not.throwException();51 expect(function () {52 utilx.Object.CheckObjectCoercible('x');53 }).to.not.throwException();54 expect(function () {55 utilx.Object.CheckObjectCoercible(required.noop);56 }).to.not.throwException();57 expect(function () {58 utilx.Object.CheckObjectCoercible(new RegExp('y'));59 }).to.not.throwException();60 expect(function () {61 utilx.Object.CheckObjectCoercible(new Date());62 }).to.not.throwException();63 });64 });...
01-Initialising.js
Source:01-Initialising.js
...15 describe('Basic tests', function () {16 it('Initialise', function () {17 expect(function () {18 reiterate();19 }).to.not.throwException();20 expect(function () {21 reiterate(undefined);22 }).to.not.throwException();23 expect(function () {24 reiterate(null);25 }).to.not.throwException();26 expect(function () {27 reiterate(0);28 }).to.not.throwException();29 expect(function () {30 reiterate(false);31 }).to.not.throwException();32 expect(function () {33 reiterate('');34 }).to.not.throwException();35 expect(function () {36 reiterate([]);37 }).to.not.throwException();38 expect(function () {39 reiterate({});40 }).to.not.throwException();41 expect(function () {42 reiterate(function () {});43 }).to.not.throwException();44 expect(function () {45 reiterate(new reiterate.$.Map());46 }).to.not.throwException();47 expect(function () {48 reiterate(new reiterate.$.Set());49 }).to.not.throwException();50 expect(function () {51 reiterate(/a\ regex/);52 }).to.not.throwException();53 });54 });...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('text=Get started');7 await page.waitForSelector('text=API');8 await page.click('text=API');9 await page.throwException(new Error('Test Error'));10 await page.screenshot({ path: `example.png` });11 await browser.close();12})();13 at Page.throwException (C:\Users\sharm\Desktop\Playwright\test.js:19:14)14 at processTicksAndRejections (internal/process/task_queues.js:93:5)15 at async main (C:\Users\sharm\Desktop\Playwright\test.js:26:3)
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.evaluate(() => window.__playwright__internal__throwException('Test'));6 await browser.close();7})();8 at Object.throwException (/home/akshay/Playground/playwrighttest/node_modules/playwright/lib/server/cjs/entry.js:77:9)9 at Page.evaluate (/home/akshay/Playground/playwrighttest/node_modules/playwright/lib/server/cjs/entry.js:155:15)10 at processTicksAndRejections (internal/process/task_queues.js:93:5)11try {12 await page.evaluate(() => window.__playwright__internal__throwException('Test'));13} catch (error) {14 console.log('error');15}16page.on('pageerror', error => {17 console.log(error);18});19page.on('error', error => {20 console.log(error);21});22page.on('crash', error => {23 console.log(error);24});
Using AI Code Generation
1const { test, expect } = require('@playwright/test');2test('test', async ({ page }) => {3 try {4 } catch (e) {5 console.log('exception thrown');6 e.throwException();7 }8});9console.log(e.message);10console.log(e.stack);11 at async FrameManager.waitForSignalsCreatedBy (/home/ankush/Projects/playwright-test/node_modules/playwright-core/lib/server/frameManager.js:136:7)12 at async FrameManager.waitForSignals (/home/ankush/Projects/playwright-test/node_modules/playwright-core/lib/server/frameManager.js:109:7)13 at async Frame.waitForNavigation (/home/ankush/Projects/playwright-test/node_modules/playwright-core/lib/server/frame.js:134:7)14 at async Page.goto (/home/ankush/Projects/playwright-test/node_modules/playwright-core/lib/server/page.js:132:7)
Using AI Code Generation
1const { throwException } = require('playwright/lib/internal/stackTrace');2throwException('Error Message');3const { throwException } = require('playwright/lib/internal/stackTrace');4throwException('Error Message');5const { throwException } = require('playwright/lib/internal/stackTrace');6throwException('Error Message');7const { throwException } = require('playwright/lib/internal/stackTrace');8throwException('Error Message');9const { throwException } = require('playwright/lib/internal/stackTrace');10throwException('Error Message');11const { throwException } = require('playwright/lib/internal/stackTrace');12throwException('Error Message');13const { throwException } = require('playwright/lib/internal/stackTrace');14throwException('Error Message');15const { throwException } = require('playwright/lib/internal/stackTrace');16throwException('Error Message');17const { throwException } = require('playwright/lib/internal/stackTrace');18throwException('Error Message');19const { throwException } = require('playwright/lib/internal/stackTrace');20throwException('Error Message');21const { throwException } = require('playwright/lib/internal/stackTrace');22throwException('Error Message');23const { throwException } = require('playwright/lib/internal/stackTrace');24throwException('Error Message');25const { throwException } = require('playwright/lib/internal/stackTrace');26throwException('Error Message');27const { throwException } = require('playwright/lib/internal/stackTrace');28throwException('Error Message');29const { throwException } = require
Using AI Code Generation
1const { InternalError } = require("playwright/lib/internal/errors");2const error = new InternalError("Test Error");3throw error;4const { TimeoutError } = require("playwright/lib/internal/errors");5const error = new TimeoutError("Test Error");6throw error;7const { BrowserError } = require("playwright/lib/internal/errors");8const error = new BrowserError("Test Error");9throw error;10const { BrowserContextError } = require("playwright/lib/internal/errors");11const error = new BrowserContextError("Test Error");12throw error;13const { PageError } = require("playwright/lib/internal/errors");14const error = new PageError("Test Error");15throw error;16const { ElementHandleError } = require("playwright/lib/internal/errors");17const error = new ElementHandleError("Test Error");18throw error;19const { TimeoutError } = require("playwright/lib/internal/errors");20const error = new TimeoutError("Test Error");21throw error;22const { Error } = require("playwright/lib/internal/errors");23const error = new Error("Test Error");24throw error;25const { Error } =
Using AI Code Generation
1const playwright = require('playwright')2const { InternalError } = playwright.errors;3throw new InternalError('My Error', 'My Error Message');4const playwright = require('playwright')5const { TimeoutError } = playwright.errors;6throw new TimeoutError('My Error Message');7const playwright = require('playwright')8const { Error } = playwright.errors;9throw new Error('My Error Message');10const playwright = require('playwright')11const { BrowserError } = playwright.errors;12throw new BrowserError('My Error Message');13const playwright = require('playwright')14const { ElementHandleError } = playwright.errors;15throw new ElementHandleError('My Error Message');16const playwright = require('playwright')17const { FrameError } = playwright.errors;18throw new FrameError('My Error Message');19const playwright = require('playwright')20const { PageError } = playwright.errors;21throw new PageError('My Error Message');22const playwright = require('playwright')23const { TimeoutError } = playwright.errors;24throw new TimeoutError('My Error Message');25const playwright = require('playwright')26const { WaitTaskError } = playwright.errors;27throw new WaitTaskError('My Error Message');28const playwright = require('playwright')29const { RequestError } = playwright.errors;30throw new RequestError('My Error Message');31const playwright = require('playwright')32const { ResponseError } = playwright.errors;33throw new ResponseError('My Error Message');34const playwright = require('playwright')35const { RouteError } = playwright.errors;36throw new RouteError('My Error Message');37const playwright = require('playwright')
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!