Best JavaScript code snippet using playwright-internal
should.min.js
Source:should.min.js
...194 proxied: function() {195 return "function" == typeof Proxy ? new Proxy(this, {196 get: function(t, e) {197 if (e in t) return t[e];198 throw new Error("Assertion has no property " + o.formatProp(e))199 }200 }) : this201 }202 }, e.exports = r203 }, {204 "./assertion-error": 2,205 "./util": 17,206 "should-format": 19207 }],208 4: [function(t, e) {209 var r = {210 checkProtoEql: !1211 };212 e.exports = r213 }, {}],214 5: [function(t, e) {215 function r(t, e, n, o, a) {216 var i = new s(t);217 i.params = {218 operator: o,219 expected: e,220 message: n,221 stackStartFunction: a || r222 }, i.fail()223 }224 function n(t, e) {225 t || r(t, !0, e, "==", c.ok)226 }227 function o(t, e) {228 return t && e ? "[object RegExp]" == Object.prototype.toString.call(e) ? e.test(t) : t instanceof e ? !0 : e.call({}, t) === !0 ? !0 : !1 : !1229 }230 function a(t, e, n, a) {231 var s;232 "string" == typeof n && (a = n, n = null);233 try {234 e()235 } catch (i) {236 s = i237 }238 if (a = (n && n.name ? " (" + n.name + ")" : ".") + (a ? " " + a : "."), t && !s && r(s, n, "Missing expected exception" + a), !t && o(s, n) && r(s, n, "Got unwanted exception" + a), t && s && n && !o(s, n) || !t && s) throw s239 }240 var s = (t("./../util"), t("./../assertion")),241 i = t("should-equal"),242 u = Array.prototype.slice,243 c = e.exports = n;244 c.fail = r, c.ok = n, c.equal = function(t, e, n) {245 t != e && r(t, e, n, "==", c.equal)246 }, c.notEqual = function(t, e, n) {247 t == e && r(t, e, n, "!=", c.notEqual)248 }, c.deepEqual = function(t, e, n) {249 i(t, e).result || r(t, e, n, "deepEqual", c.deepEqual)250 }, c.notDeepEqual = function(t, e, n) {251 i(t, e).result && r(t, e, n, "notDeepEqual", c.notDeepEqual)252 }, c.strictEqual = function(t, e, n) {253 t !== e && r(t, e, n, "===", c.strictEqual)254 }, c.notStrictEqual = function(t, e, n) {255 t === e && r(t, e, n, "!==", c.notStrictEqual)256 }, c["throws"] = function() {257 a.apply(this, [!0].concat(u.call(arguments)))258 }, c.doesNotThrow = function() {259 a.apply(this, [!1].concat(u.call(arguments)))260 }, c.ifError = function(t) {261 if (t) throw t262 }263 }, {264 "./../assertion": 3,265 "./../util": 17,266 "should-equal": 18267 }],268 6: [function(t, e) {269 var r = t("../util"),270 n = t("./_assert"),271 o = t("../assertion-error");272 e.exports = function(t) {273 var e = t.format;274 r.merge(t, n), t.exist = t.exists = function(r, n) {275 if (null == r) throw new o({276 message: n || "expected " + e(r) + " to exist",277 stackStartFunction: t.exist278 })279 }, t.not = {}, t.not.exist = t.not.exists = function(r, n) {280 if (null != r) throw new o({281 message: n || "expected " + e(r) + " to not exist",282 stackStartFunction: t.not.exist283 })284 }285 }286 }, {287 "../assertion-error": 2,288 "../util": 17,289 "./_assert": 5290 }],291 7: [function(t, e) {292 e.exports = function(t, e) {293 e.add("true", function() {294 this.is.exactly(!0)295 }, !0), e.alias("true", "True"), e.add("false", function() {296 this.is.exactly(!1)297 }, !0), e.alias("false", "False"), e.add("ok", function() {298 this.params = {299 operator: "to be truthy"300 }, this.assert(this.obj)301 }, !0)302 }303 }, {}],304 8: [function(t, e) {305 e.exports = function(t, e) {306 ["an", "of", "a", "and", "be", "have", "with", "is", "which", "the"].forEach(function(t) {307 e.addChain(t)308 })309 }310 }, {}],311 9: [function(t, e) {312 var r = t("../util"),313 n = t("should-equal");314 e.exports = function(t, e) {315 var o = t.format,316 a = t.type;317 e.add("containEql", function(e) {318 this.params = {319 operator: "to contain " + o(e)320 }, this.is.not["null"].and.not.undefined;321 var a = this.obj,322 s = t.type(a);323 s == t.type.STRING ? this.assert(a.indexOf(String(e)) >= 0) : r.isIndexable(a) ? this.assert(r.some(a, function(t) {324 return n(t, e).result325 })) : this.have.properties(e)326 }), e.add("containDeepOrdered", function(e) {327 this.params = {328 operator: "to contain " + o(e)329 };330 var n = this.obj;331 if (a(n) == a.STRING) this.assert(n.indexOf(String(e)) >= 0);332 else if (r.isIndexable(n) && r.isIndexable(e)) {333 for (var s = 0, i = 0, u = r.length(n), c = r.length(e); u > s && c > i; s++) try {334 t(n[s]).containDeepOrdered(e[i]), i++335 } catch (l) {336 if (l instanceof t.AssertionError) continue;337 throw l338 }339 this.assert(i == c)340 } else null != n && null != e && "object" == typeof n && "object" == typeof e ? (r.forEach(e, function(e, r) {341 t(n[r]).containDeepOrdered(e)342 }), r.isEmptyObject(e) && this.eql(e)) : this.eql(e)343 }), e.add("containDeep", function(e) {344 this.params = {345 operator: "to contain " + o(e)346 };347 var n = this.obj;348 if ("string" == typeof n) this.assert(n.indexOf(String(e)) >= 0);349 else if (r.isIndexable(n) && r.isIndexable(e)) {350 var a = {};351 r.forEach(e, function(e) {352 this.assert(r.some(n, function(r, n) {353 if (n in a) return !1;354 try {355 return t(r).containDeep(e), a[n] = !0, !0356 } catch (o) {357 if (o instanceof t.AssertionError) return !1;358 throw o359 }360 }))361 }, this)362 } else null != n && null != e && "object" == typeof n && "object" == typeof e ? (r.forEach(e, function(e, r) {363 t(n[r]).containDeep(e)364 }), r.isEmptyObject(e) && this.eql(e)) : this.eql(e)365 })366 }367 }, {368 "../util": 17,369 "should-equal": 18370 }],371 10: [function(t, e) {372 function r(t, e, r, n) {373 return ((t.path.length > 0 ? "at " + t.path.map(a.formatProp).join(" -> ") : "") + (t.a === e ? "" : ", A has " + n(t.a)) + (t.b === r ? "" : " and B has " + n(t.b)) + (t.showReason ? " because " + t.reason : "")).trim()374 }375 var n = t("should-equal"),376 o = t("should-type"),377 a = t("../util");378 e.exports = function(t, e) {379 e.add("eql", function(e, a) {380 this.params = {381 operator: "to equal",382 expected: e,383 message: a384 };385 var s = n(this.obj, e, t.config);386 this.params.details = s.result ? "" : r(s, this.obj, e, t.format), this.params.showDiff = o(this.obj) == o(e), this.assert(s.result)387 }), e.add("equal", function(t, e) {388 this.params = {389 operator: "to be",390 expected: t,391 message: e392 }, this.params.showDiff = o(this.obj) == o(t), this.assert(t === this.obj)393 }), e.alias("equal", "exactly")394 }395 }, {396 "../util": 17,397 "should-equal": 18,398 "should-type": 20399 }],400 11: [function(t, e) {401 var r = t("../util");402 e.exports = function(t, e) {403 var n = t.format;404 e.add("throw", function(e, o) {405 var a = this.obj,406 s = {},407 i = "",408 u = !1;409 this.is.a.Function;410 var c = !0;411 try {412 a()413 } catch (l) {414 u = !0, s = l415 }416 if (u)417 if (e) {418 if ("string" == typeof e) c = e == s.message;419 else if (e instanceof RegExp) c = e.test(s.message);420 else if ("function" == typeof e) c = s instanceof e;421 else if (null != e) try {422 s.should.match(e)423 } catch (l) {424 if (!(l instanceof t.AssertionError)) throw l;425 i = ": " + l.message, c = !1426 }427 if (c) {428 if ("function" == typeof e && o) try {429 s.should.match(o)430 } catch (l) {431 if (!(l instanceof t.AssertionError)) throw l;432 i = ": " + l.message, c = !1433 }434 } else "string" == typeof e || e instanceof RegExp ? i = " with a message matching " + n(e) + ", but got '" + s.message + "'" : "function" == typeof e && (i = " of type " + r.functionName(e) + ", but got " + r.functionName(s.constructor))435 } else i = " (got " + n(s) + ")";436 this.params = {437 operator: "to throw exception" + i438 }, this.assert(u), this.assert(c)439 }), e.alias("throw", "throwError")440 }441 }, {442 "../util": 17443 }],444 12: [function(t, e) {445 var r = t("../util"),446 n = t("should-equal");447 e.exports = function(t, e) {448 var o = t.format;449 e.add("match", function(e, a) {450 if (this.params = {451 operator: "to match " + o(e),452 message: a453 }, !n(this.obj, e).result)454 if (e instanceof RegExp) {455 if ("string" == typeof this.obj) this.assert(e.exec(this.obj));456 else if (r.isIndexable(this.obj)) r.forEach(this.obj, function(t) {457 this.assert(e.exec(t))458 }, this);459 else if (null != this.obj && "object" == typeof this.obj) {460 var s = [],461 i = [];462 r.forEach(this.obj, function(t, n) {463 e.exec(t) ? i.push(r.formatProp(n)) : s.push(r.formatProp(n) + " (" + o(t) + ")")464 }, this), s.length && (this.params.operator += "\n not matched properties: " + s.join(", ")), i.length && (this.params.operator += "\n matched properties: " + i.join(", ")), this.assert(0 == s.length)465 }466 } else if ("function" == typeof e) {467 var u;468 u = e(this.obj), "boolean" == typeof u && this.assert(u)469 } else null != e && "object" == typeof e ? (s = [], i = [], r.forEach(e, function(e, n) {470 try {471 t(this.obj[n]).match(e), i.push(r.formatProp(n))472 } catch (a) {473 if (!(a instanceof t.AssertionError)) throw a;474 s.push(r.formatProp(n) + " (" + o(this.obj[n]) + ")")475 }476 }, this), s.length && (this.params.operator += "\n not matched properties: " + s.join(", ")), i.length && (this.params.operator += "\n matched properties: " + i.join(", ")), this.assert(0 == s.length)) : this.assert(!1)477 }), e.add("matchEach", function(t, e) {478 this.params = {479 operator: "to match each " + o(t),480 message: e481 };482 var a = t;483 t instanceof RegExp ? a = function(e) {484 return !!t.exec(e)485 } : "function" != typeof t && (a = function(e) {486 return n(e, t).result487 }), r.forEach(this.obj, function(t, e) {488 var r = a(t, e);489 "boolean" == typeof r && this.assert(r)490 }, this)491 })492 }493 }, {494 "../util": 17,495 "should-equal": 18496 }],497 13: [function(t, e) {498 e.exports = function(t, e) {499 e.add("NaN", function() {500 this.params = {501 operator: "to be NaN"502 }, this.assert(this.obj !== this.obj)503 }, !0), e.add("Infinity", function() {504 this.params = {505 operator: "to be Infinity"506 }, this.is.a.Number.and.not.a.NaN.and.assert(!isFinite(this.obj))507 }, !0), e.add("within", function(t, e, r) {508 this.params = {509 operator: "to be within " + t + ".." + e,510 message: r511 }, this.assert(this.obj >= t && this.obj <= e)512 }), e.add("approximately", function(t, e, r) {513 this.params = {514 operator: "to be approximately " + t + " ±" + e,515 message: r516 }, this.assert(Math.abs(this.obj - t) <= e)517 }), e.add("above", function(t, e) {518 this.params = {519 operator: "to be above " + t,520 message: e521 }, this.assert(this.obj > t)522 }), e.add("below", function(t, e) {523 this.params = {524 operator: "to be below " + t,525 message: e526 }, this.assert(this.obj < t)527 }), e.alias("above", "greaterThan"), e.alias("below", "lessThan")528 }529 }, {}],530 14: [function(t, e) {531 var r = t("../util"),532 n = t("should-equal"),533 o = Array.prototype.slice;534 e.exports = function(t, e) {535 function a() {536 var e = {};537 if (arguments.length > 1) e.names = o.call(arguments);538 else {539 var n = arguments[0],540 a = t.type(n);541 a == t.type.STRING ? e.names = [n] : r.isIndexable(n) ? e.names = n : (e.names = Object.keys(n), e.values = n)542 }543 return e544 }545 var s = t.format;546 e.add("propertyWithDescriptor", function(e, r) {547 this.params = {548 actual: this.obj,549 operator: "to have own property with descriptor " + s(r)550 };551 var n = this.obj;552 this.have.ownProperty(e), t(Object.getOwnPropertyDescriptor(Object(n), e)).have.properties(r)553 }), e.add("enumerable", function(t, e) {554 t = String(t), this.params = {555 operator: "to have enumerable property " + r.formatProp(t) + (arguments.length > 1 ? " equal to " + s(e) : "")556 };557 var n = {558 enumerable: !0559 };560 arguments.length > 1 && (n.value = e), this.have.propertyWithDescriptor(t, n)561 }), e.add("enumerables", function() {562 var t = a.apply(null, arguments);563 this.params = {564 operator: "to have enumerables " + t.names.map(r.formatProp)565 };566 var e = this.obj;567 t.names.forEach(function(t) {568 e.should.have.enumerable(t)569 })570 }), e.add("property", function(t, e) {571 if (t = String(t), arguments.length > 1) {572 var r = {};573 r[t] = e, this.have.properties(r)574 } else this.have.properties(t);575 this.obj = this.obj[t]576 }), e.add("properties", function(t) {577 var e = {};578 arguments.length > 1 ? t = o.call(arguments) : Array.isArray(t) || ("string" == typeof t ? t = [t] : (e = t, t = Object.keys(t)));579 var a = Object(this.obj),580 i = [];581 t.forEach(function(t) {582 t in a || i.push(r.formatProp(t))583 });584 var u = i;585 0 === u.length ? u = t.map(r.formatProp) : this.anyOne && (u = t.filter(function(t) {586 return i.indexOf(r.formatProp(t)) < 0587 }).map(r.formatProp));588 var c = (1 === u.length ? "to have property " : "to have " + (this.anyOne ? "any of " : "") + "properties ") + u.join(", ");589 this.params = {590 obj: this.obj,591 operator: c592 }, this.assert(0 === i.length || this.anyOne && i.length != t.length);593 var l = Object.keys(e);594 if (l.length) {595 var h = [];596 u = [], l.forEach(function(t) {597 var o = e[t];598 n(a[t], o).result ? u.push(r.formatProp(t) + " of " + s(o)) : h.push(r.formatProp(t) + " of " + s(o) + " (got " + s(a[t]) + ")")599 }), (0 !== h.length && !this.anyOne || this.anyOne && 0 === u.length) && (u = h), c = (1 === u.length ? "to have property " : "to have " + (this.anyOne ? "any of " : "") + "properties ") + u.join(", "), this.params = {600 obj: this.obj,601 operator: c602 }, this.assert(0 === h.length || this.anyOne && h.length != l.length)603 }604 }), e.add("length", function(t, e) {605 this.have.property("length", t, e)606 }), e.alias("length", "lengthOf");607 var i = Object.prototype.hasOwnProperty;608 e.add("ownProperty", function(t, e) {609 t = String(t), this.params = {610 actual: this.obj,611 operator: "to have own property " + r.formatProp(t),612 message: e613 }, this.assert(i.call(this.obj, t)), this.obj = this.obj[t]614 }), e.alias("ownProperty", "hasOwnProperty"), e.add("empty", function() {615 if (this.params = {616 operator: "to be empty"617 }, void 0 !== r.length(this.obj)) this.obj.should.have.property("length", 0);618 else {619 var t = Object(this.obj);620 for (var e in t) this.obj.should.not.have.ownProperty(e)621 }622 }, !0), e.add("keys", function(e) {623 arguments.length > 1 ? e = o.call(arguments) : 1 === arguments.length && t.type(e) == t.type.STRING ? e = [e] : 0 === arguments.length && (e = []), e = e.map(String);624 var n = Object(this.obj),625 a = [];626 e.forEach(function(t) {627 i.call(this.obj, t) || a.push(r.formatProp(t))628 }, this);629 var s = [];630 Object.keys(n).forEach(function(t) {631 e.indexOf(t) < 0 && s.push(r.formatProp(t))632 });633 var u = 0 === e.length ? "to be empty" : "to have " + (1 === e.length ? "key " : "keys ");634 this.params = {635 operator: u + e.map(r.formatProp).join(", ")636 }, a.length > 0 && (this.params.operator += "\n missing keys: " + a.join(", ")), s.length > 0 && (this.params.operator += "\n extra keys: " + s.join(", ")), this.assert(0 === a.length && 0 === s.length)637 }), e.alias("keys", "key"), e.add("propertyByPath", function(e) {638 arguments.length > 1 ? e = o.call(arguments) : 1 === arguments.length && r.isString(e) ? e = [e] : 0 === arguments.length && (e = []);639 var n = e.map(r.formatProp);640 e = e.map(String);641 for (var a, s = t(Object(this.obj)), i = []; a = e.shift();) this.params = {642 operator: "to have property by path " + n.join(", ") + " - failed on " + r.formatProp(a)643 }, s = s.have.property(a), i.push(a);644 this.params = {645 obj: this.obj,646 operator: "to have property by path " + n.join(", ")647 }, this.obj = s.obj648 })649 }650 }, {651 "../util": 17,652 "should-equal": 18653 }],654 15: [function(t, e) {655 e.exports = function(t, e) {656 e.add("startWith", function(e, r) {...
diff.js
Source:diff.js
...180 ret.push( ...expandObjects(181 {182 path: path,183 oldValue: null,184 newValue: formatProp( op.path, op.value )185 }186 ) );187 basisPtr.set( op.path, op.value );188 } else if ( op.op === 'remove' ) {189 let newValue = null;190 // Check for array element removal and show new value if removed191 // element was not array tail.192 const parentPath = path.slice( 0, -1 );193 const parent = safePointerGet( basisPtr, parentPath );194 const curIdx = path[ path.length - 1 ];195 if (196 Array.isArray( parent ) &&197 typeof curIdx === 'number' &&198 ( curIdx + 1 ) < parent.length199 ) {200 const nextPath = [ ...parentPath, curIdx + 1 ];201 newValue = formatProp(202 pointer.compile( nextPath ),203 safePointerGet( basisPtr, nextPath )204 );205 }206 ret.push( ...expandObjects(207 {208 path: path,209 oldValue: formatProp(210 op.path, safePointerGet( basisPtr, op.path )211 ),212 newValue: newValue213 }214 ) );215 basisPtr.remove( op.path );216 } else if ( op.op === 'replace' ) {217 ret.push( ...expandObjects(218 {219 path: path,220 oldValue: formatProp(221 op.path, safePointerGet( basisPtr, op.path )222 ),223 newValue: formatProp( op.path, op.value )224 }225 ) );226 basisPtr.set( op.path, op.value );227 } else if ( op.op === 'move' ) {228 const fromProp = formatProp(229 op.from, safePointerGet( basisPtr, op.from )230 );231 ret.push( ...expandObjects(232 {233 path: path,234 oldValue: formatProp(235 op.path, safePointerGet( basisPtr, op.path )236 ),237 newValue: fromProp238 }239 ) );240 ret.push( ...expandObjects(241 {242 path: parsePath( op.from ),243 oldValue: fromProp,244 newValue: null245 }246 ) );247 basisPtr.set( op.path, safePointerGet( basisPtr, op.from ) );248 basisPtr.remove( op.from );249 } else if ( op.op === 'copy' ) {250 const fromVal = safePointerGet( basisPtr, op.from );251 const oldValue = formatProp(252 op.path, safePointerGet( basisPtr, op.path )253 );254 ret.push( ...expandObjects(255 {256 path: path,257 oldValue: oldValue,258 newValue: formatProp( op.path, fromVal )259 }260 ) );261 basisPtr.set( op.path, fromVal );262 }263 return ret;264}265/**266 * Compare two change records for sort order.267 *268 * @param {Object} a - First element269 * @param {Object} b - Second element270 * @return {number}271 */272export function compareChanges( a, b ) {...
property.js
Source:property.js
...15 Assertion.add('enumerable', function(name, val) {16 name = String(name);1718 this.params = {19 operator: "to have enumerable property " + util.formatProp(name)20 };2122 this.assert(this.obj.propertyIsEnumerable(name));2324 if(arguments.length > 1) {25 this.params.operator += " equal to " + i(val);26 this.assert(eql(val, this.obj[name]));27 }28 });2930 Assertion.add('property', function(name, val) {31 name = String(name);32 if(arguments.length > 1) {33 var p = {};34 p[name] = val;35 this.have.properties(p);36 } else {37 this.have.properties(name);38 }39 this.obj = this.obj[name];40 });4142 Assertion.add('properties', function(names) {43 var values = {};44 if(arguments.length > 1) {45 names = aSlice.call(arguments);46 } else if(!util.isArray(names)) {47 if(util.isString(names)) {48 names = [names];49 } else {50 values = names;51 names = Object.keys(names);52 }53 }5455 var obj = Object(this.obj), missingProperties = [];5657 //just enumerate properties and check if they all present58 names.forEach(function(name) {59 if(!(name in obj)) missingProperties.push(util.formatProp(name));60 });6162 var props = missingProperties;63 if(props.length === 0) {64 props = names.map(util.formatProp);65 } else if(this.anyOne) {66 props = names.filter(function(name) {67 return missingProperties.indexOf(util.formatProp(name)) < 0;68 }).map(util.formatProp);69 }7071 var operator = (props.length === 1 ?72 'to have property ' : 'to have ' + (this.anyOne ? 'any of ' : '') + 'properties ') + props.join(', ');7374 this.params = {obj: this.formattedObj(), operator: operator};7576 //check that all properties presented77 //or if we request one of them that at least one them presented78 this.assert(missingProperties.length === 0 || (this.anyOne && missingProperties.length != names.length));7980 // check if values in object matched expected81 var valueCheckNames = Object.keys(values);82 if(valueCheckNames.length) {83 var wrongValues = [];84 props = [];8586 // now check values, as there we have all properties87 valueCheckNames.forEach(function(name) {88 var value = values[name];89 if(!eql(obj[name], value)) {90 wrongValues.push(util.formatProp(name) + ' of ' + i(value) + ' (got ' + i(obj[name]) + ')');91 } else {92 props.push(util.formatProp(name) + ' of ' + i(value));93 }94 });9596 if((wrongValues.length !== 0 && !this.anyOne) || (this.anyOne && props.length === 0)) {97 props = wrongValues;98 }99100 operator = (props.length === 1 ?101 'to have property ' : 'to have ' + (this.anyOne ? 'any of ' : '') + 'properties ') + props.join(', ');102103 this.params = {obj: this.formattedObj(), operator: operator};104105 //if there is no not matched values106 //or there is at least one matched107 this.assert(wrongValues.length === 0 || (this.anyOne && wrongValues.length != valueCheckNames.length));108 }109 });110111 Assertion.add('length', function(n, description) {112 this.have.property('length', n, description);113 });114115 Assertion.alias('length', 'lengthOf');116117 var hasOwnProperty = Object.prototype.hasOwnProperty;118119 Assertion.add('ownProperty', function(name, description) {120 name = String(name);121 this.params = {122 obj: this.formattedObj(),123 operator: 'to have own property ' + util.formatProp(name),124 message: description125 };126127 this.assert(hasOwnProperty.call(this.obj, name));128129 this.obj = this.obj[name];130 });131132 Assertion.alias('ownProperty', 'hasOwnProperty');133134 Assertion.add('empty', function() {135 this.params = {operator: 'to be empty'};136137 if(util.isString(this.obj) || util.isArray(this.obj) || util.isArguments(this.obj)) {138 this.obj.should.have.property('length', 0);139 } else {140 var obj = Object(this.obj); // wrap to reference for booleans and numbers141 for(var prop in obj) {142 this.obj.should.not.ownProperty(prop);143 }144 }145 }, true);146147 Assertion.add('keys', function(keys) {148 if(arguments.length > 1) keys = aSlice.call(arguments);149 else if(arguments.length === 1 && util.isString(keys)) keys = [keys];150 else if(arguments.length === 0) keys = [];151152 keys = keys.map(String);153154 var obj = Object(this.obj);155156 // first check if some keys are missing157 var missingKeys = [];158 keys.forEach(function(key) {159 if(!hasOwnProperty.call(this.obj, key))160 missingKeys.push(util.formatProp(key));161 }, this);162163 // second check for extra keys164 var extraKeys = [];165 Object.keys(obj).forEach(function(key) {166 if(keys.indexOf(key) < 0) {167 extraKeys.push(util.formatProp(key));168 }169 });170171 var verb = keys.length === 0 ? 'to be empty' :172 'to have ' + (keys.length === 1 ? 'key ' : 'keys ');173174 this.params = {operator: verb + keys.map(util.formatProp).join(', ')};175176 if(missingKeys.length > 0)177 this.params.operator += '\n\tmissing keys: ' + missingKeys.join(', ');178179 if(extraKeys.length > 0)180 this.params.operator += '\n\textra keys: ' + extraKeys.join(', ');181182 this.assert(missingKeys.length === 0 && extraKeys.length === 0);183 });184185 Assertion.alias("keys", "key");186187 Assertion.add('propertyByPath', function(properties) {188 if(arguments.length > 1) properties = aSlice.call(arguments);189 else if(arguments.length === 1 && util.isString(properties)) properties = [properties];190 else if(arguments.length === 0) properties = [];191192 var allProps = properties.map(util.formatProp);193194 properties = properties.map(String);195196 var obj = should(Object(this.obj));197198 var foundProperties = [];199200 var currentProperty;201 while(currentProperty = properties.shift()) {202 this.params = {operator: 'to have property by path ' + allProps.join(', ') + ' - failed on ' + util.formatProp(currentProperty)};203 obj = obj.have.property(currentProperty);204 foundProperties.push(currentProperty);205 }206207 this.params = {obj: this.formattedObj(), operator: 'to have property by path ' + allProps.join(', ')};208209 this.obj = obj.obj;210 });
...
formatProp.spec.js
Source:formatProp.spec.js
...13 });14 it('should format prop with only a value', () => {15 formatPropValue.mockReturnValue('"MockedPropValue"');16 expect(17 formatProp('foo', true, 'bar', false, null, true, 0, defaultOptions)18 ).toEqual({19 attributeFormattedInline: ' foo="MockedPropValue"',20 attributeFormattedMultiline: `21 foo="MockedPropValue"`,22 isMultilineAttribute: false,23 });24 expect(formatPropValue).toHaveBeenCalledWith(25 'bar',26 true,27 0,28 defaultOptions29 );30 });31 it('should format prop with only a default value', () => {32 formatPropValue.mockReturnValue('"MockedPropValue"');33 expect(34 formatProp('foo', false, null, true, 'baz', true, 0, defaultOptions)35 ).toEqual({36 attributeFormattedInline: ' foo="MockedPropValue"',37 attributeFormattedMultiline: `38 foo="MockedPropValue"`,39 isMultilineAttribute: false,40 });41 expect(formatPropValue).toHaveBeenCalledWith(42 'baz',43 true,44 0,45 defaultOptions46 );47 });48 it('should format prop with a value and a default value', () => {49 formatPropValue.mockReturnValue('"MockedPropValue"');50 expect(51 formatProp('foo', true, 'bar', true, 'baz', true, 0, defaultOptions)52 ).toEqual({53 attributeFormattedInline: ' foo="MockedPropValue"',54 attributeFormattedMultiline: `55 foo="MockedPropValue"`,56 isMultilineAttribute: false,57 });58 expect(formatPropValue).toHaveBeenCalledWith(59 'bar',60 true,61 0,62 defaultOptions63 );64 });65 it('should format a truthy boolean prop (with short syntax)', () => {66 const options = {67 useBooleanShorthandSyntax: true,68 tabStop: 2,69 };70 formatPropValue.mockReturnValue('{true}');71 expect(72 formatProp('foo', true, true, false, false, true, 0, options)73 ).toEqual({74 attributeFormattedInline: ' foo',75 attributeFormattedMultiline: `76 foo`,77 isMultilineAttribute: false,78 });79 expect(formatPropValue).toHaveBeenCalledWith(true, true, 0, options);80 });81 it('should ignore a falsy boolean prop (with short syntax)', () => {82 const options = {83 useBooleanShorthandSyntax: true,84 tabStop: 2,85 };86 formatPropValue.mockReturnValue('{false}');87 expect(88 formatProp('foo', true, false, false, null, true, 0, options)89 ).toEqual({90 attributeFormattedInline: '',91 attributeFormattedMultiline: '',92 isMultilineAttribute: false,93 });94 expect(formatPropValue).toHaveBeenCalledWith(false, true, 0, options);95 });96 it('should format a truthy boolean prop (with explicit syntax)', () => {97 const options = {98 useBooleanShorthandSyntax: false,99 tabStop: 2,100 };101 formatPropValue.mockReturnValue('{true}');102 expect(103 formatProp('foo', true, true, false, false, true, 0, options)104 ).toEqual({105 attributeFormattedInline: ' foo={true}',106 attributeFormattedMultiline: `107 foo={true}`,108 isMultilineAttribute: false,109 });110 expect(formatPropValue).toHaveBeenCalledWith(true, true, 0, options);111 });112 it('should format a falsy boolean prop (with explicit syntax)', () => {113 const options = {114 useBooleanShorthandSyntax: false,115 tabStop: 2,116 };117 formatPropValue.mockReturnValue('{false}');118 expect(119 formatProp('foo', true, false, false, false, true, 0, options)120 ).toEqual({121 attributeFormattedInline: ' foo={false}',122 attributeFormattedMultiline: `123 foo={false}`,124 isMultilineAttribute: false,125 });126 expect(formatPropValue).toHaveBeenCalledWith(false, true, 0, options);127 });128 it('should format a mulitline props', () => {129 formatPropValue.mockReturnValue(`{[130"a",131"b"132]}`);133 expect(134 formatProp(135 'foo',136 true,137 ['a', 'b'],138 false,139 false,140 false,141 0,142 defaultOptions143 )144 ).toEqual({145 attributeFormattedInline: ` foo={[146"a",147"b"148]}`,149 attributeFormattedMultiline: `150 foo={[151"a",152"b"153]}`,154 isMultilineAttribute: true,155 });156 expect(formatPropValue).toHaveBeenCalledWith(157 ['a', 'b'],158 false,159 0,160 defaultOptions161 );162 });163 it('should indent the formatted string', () => {164 /*165 * lvl 4 and tabStop 2 :166 * - 4 * 2 = 8 spaces167 * - One new indentation = 2 spaces168 * - Expected indentation : 10 spaces169 */170 const options = {171 useBooleanShorthandSyntax: true,172 tabStop: 2,173 };174 formatPropValue.mockReturnValue('"MockedPropValue"');175 expect(176 formatProp('foo', true, 'bar', false, null, true, 4, options)177 ).toEqual({178 attributeFormattedInline: ' foo="MockedPropValue"',179 attributeFormattedMultiline: `180 foo="MockedPropValue"`, // 10 spaces181 isMultilineAttribute: false,182 });183 expect(formatPropValue).toHaveBeenCalledWith('bar', true, 4, options);184 });...
formatter.js
Source:formatter.js
...85 if (format.substr(i, 4) === "yyyy") {86 result += y;87 i += 3;88 } else if (format[i + 1] === "y") {89 result += formatProp(y % 100, true);90 i++;91 }92 break;93 case "m":94 const isMNext = format[i + 1] === "m";95 if (afterH) {96 result += formatProp(min, isMNext);97 if (isMNext) {98 i++;99 }100 } else {101 if (format.substr(i, 4) === "mmmm") {102 result += month[m - 1];103 i += 3;104 } else if (format.substr(i, 3) === "mmm") {105 result += month[m - 1].substr(0, 3);106 i += 2;107 } else {108 result += formatProp(m, isMNext);109 if (isMNext) {110 i++;111 }112 }113 }114 break;115 case "d":116 if (format.substr(i, 4) === "dddd") {117 result += weekdays[w];118 i += 3;119 } else if (format.substr(i, 3) === "ddd") {120 result += weekdays[w].substr(0, 3);121 i += 2;122 } else {123 const isDNext = format[i + 1] === "d";124 result += formatProp(d, isDNext);125 if (isDNext) {126 i++;127 }128 }129 break;130 case "h":131 afterH = true;132 const isHNext = format[i + 1] === "h";133 result += formatProp(ampm !== -1 ? h % 12 || 12 : h, isHNext);134 if (isHNext) {135 i++;136 }137 break;138 case "s":139 const isSNext = format[i + 1] === "s";140 result += formatProp(s, isSNext);141 if (isSNext) {142 i++;143 }144 break;145 case "@":146 case ";":147 case "\\":148 break;149 default:150 result += format[i];151 }152 }153 return result;154}155export function formatCell(value, format) {156 if (isNaN(value)) {157 return value;158 }159 const float = parseFloat(value);160 switch (format) {161 case "General":162 return value;163 case "0.00":164 return value.toFixed(2);165 case "0%":166 return Math.round(float) + "%";167 case "0.00%":168 return float.toFixed(2) + "%";169 case "0.00E+00":170 const e = Math.ceil(Math.log(10, float)) + 1;171 return `${(float / Math.pow(10, e)).toFixed(2)}E${e > 0 ? "+" : ""}${formatProp(e, true)}`172 default:173 return tryFormatAsDate(float, format);174 }...
pod.dao.js
Source:pod.dao.js
...67 )68 // Merging manifesto and Actions69 const fullPod = R.merge(70 {71 Actions: formatProp(actions),72 PodAuths: formatProp(podAuths),73 },74 manifesto,75 )76 Pod.create(fullPod, {77 include: [models.Action, models.PodAuth],78 })79 .then(res)80 .catch(rej)81 })82/**83 * Delete all pods with ids84 * @param ids85 */86export const deletePods = ids =>...
reactElementToString.js
Source:reactElementToString.js
...46 .filter(k => (defaultProps ? props[k] !== defaultProps[k] : true));47 let propString = "";48 try {49 propString = propKeys50 .map(k => formatProp(k, props[k]))51 .join(`\n${indent} `);52 } catch (e) {53 return `Couldn't stringify React Element. Try setting \`sourceText\` explicitly or use \`noSource\`.54${e}`;55 }56 const whitespaceBeforeProps =57 propKeys.length > 1 // eslint-disable-line no-nested-ternary58 ? `\n${indent} `59 : propKeys.length === 1 ? " " : "";60 const whitespaceAfterProps = propKeys.length > 1 ? `\n${indent}` : "";61 return props.children62 ? `${indent}<${displayName}${whitespaceBeforeProps}${propString}${whitespaceAfterProps}>63${React.Children.map(props.children, c =>64 reactElementToString(c, `${indent} `)...
index.js
Source:index.js
...12 document.body.removeChild(instance.$el);13 instance = null;14 }, 250);15}16function formatProp(type, defaultValue) {17 return {18 type: type,19 default: defaultValue20 }21}22function toString(value) {23 return Object.prototype.toString.call(value);24}25Vue.prototype.$confirm = function (data) {26 let options = {props: {}};27 let loading = false;28 if (toString(data) === "[object Object]") {29 for (let key in data) {30 if (data.hasOwnProperty(key)) {31 let value = data[key];32 if (key === "loading") {33 loading = value34 } else {35 options.props[key] = formatProp(value.constructor, value);36 }37 }38 }39 } else if (toString(data) === "[object String]") {40 options.props.content = formatProp(String, data);41 } else {42 throw new Error("options must be a string or object.");43 }44 return new Promise((resolve, reject) => {45 let instance = getInstance(Popup, options);46 instance.$on("submit", function () {47 if (loading) {48 this.loading = true;49 let hideLoading = () => {50 this.loading = false;51 };52 let done = () => {53 this.loading = false;54 destroy(this);...
Using AI Code Generation
1const { formatProp } = require('@playwright/test/lib/utils/stackTrace');2const { formatProp } = require('@playwright/test/lib/utils/stackTrace');3const { formatProp } = require('@playwright/test/lib/utils/stackTrace');4const { it, test } = require('@playwright/test');5const { it, test } = require('@playwright/test');6const { it, test } = require('@playwright/test');7const { expect } = require('@playwright/test');8const { expect } = require('@playwright/test');9const { expect } = require('@playwright/test');
Using AI Code Generation
1const { formatProp } = require('playwright/lib/utils/utils');2const { chromium } = require('playwright');3async function main() {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const selector = formatProp('selector', 'input[name="q"]');8 const element = await page.$(selector);9 await element.type('Hello World');10 await browser.close();11}12main();
Using AI Code Generation
1const { formatProp } = require('playwright/lib/server/frames');2const obj = {3}4console.log(formatProp(obj));5{"a":1,"b":2,"c":3}6const { formatProp } = require('playwright/lib/server/frames');7const obj = {8}9console.log(formatProp(obj));10{"a":1,"b":2,"c":3}11const { formatProp } = require('playwright/lib/server/frames');12const obj = {13}14console.log(formatProp(obj));15{"a":1,"b":2,"c":3}16const { formatProp } = require('playwright/lib/server/frames');17const obj = {18}19console.log(formatProp(obj));20{"a":1,"b":2,"c":3}
Using AI Code Generation
1const { formatProp } = require('playwright/lib/internal/locators/locators');2console.log(formatProp('text', 'Hello World'));3console.log(formatProp('value', 'Hello World'));4console.log(formatProp('placeholder', 'Hello World'));5console.log(formatProp('alt', 'Hello World'));6console.log(formatProp('title', 'Hello World'));7console.log(formatProp('aria-label', 'Hello World'));8console.log(formatProp('aria-labelledby', 'Hello World'));9console.log(formatProp('role', 'Hello World'));10console.log(formatProp('id', 'Hello World'));11console.log(formatProp('name', 'Hello World'));12console.log(formatProp('href', 'Hello World'));13console.log(formatProp('src', 'Hello World'));14console.log(formatProp('data-test-id', 'Hello World'));15console.log(formatProp('data-test', 'Hello World'));16console.log(formatProp('data-testid', 'Hello World'));17console.log(formatProp('data-test-id', 'Hello World'));18console.log(formatProp('data-test', 'Hello World'));19console.log(formatProp('data-testid', 'Hello World'));20console.log(formatProp('data-test-id', 'Hello World'));21console.log(formatProp('data-test', 'Hello World'));22console.log(formatProp('data-testid', 'Hello World'));23console.log(formatProp('data-test-id', 'Hello World'));24console.log(formatProp('data-test
Using AI Code Generation
1const { formatProp } = require('@playwright/test/lib/server/frames');2const { assert } = require('chai');3const prop = {4};5const expected = {6};7describe('formatProp', () => {8 it('should return the same prop', () => {9 const result = formatProp(prop);10 assert.deepEqual(result, expected);11 });12});
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!!