How to use uniqueStringsAndSymbols method in unexpected

Best JavaScript code snippet using unexpected

types.js

Source:types.js Github

copy

Full Screen

1const utils = require('./utils');2const isRegExp = utils.isRegExp;3const leftPad = utils.leftPad;4const arrayChanges = require('array-changes');5const ukkonen = require('ukkonen');6const detectIndent = require('detect-indent');7const defaultDepth = require('./defaultDepth');8const AssertionString = require('./AssertionString');9module.exports = function (expect) {10 expect.addType({11 name: 'wrapperObject',12 identify: false,13 equal(a, b, equal) {14 return a === b || equal(this.unwrap(a), this.unwrap(b));15 },16 inspect(value, depth, output, inspect) {17 output.append(this.prefix(output.clone(), value));18 output.append(inspect(this.unwrap(value), depth));19 output.append(this.suffix(output.clone(), value));20 return output;21 },22 diff(actual, expected, output, diff, inspect) {23 output.inline = true;24 actual = this.unwrap(actual);25 expected = this.unwrap(expected);26 const comparison = diff(actual, expected);27 const prefixOutput = this.prefix(output.clone(), actual);28 const suffixOutput = this.suffix(output.clone(), actual);29 if (comparison && comparison.inline) {30 return output31 .append(prefixOutput)32 .append(comparison)33 .append(suffixOutput);34 } else {35 return output36 .append(prefixOutput)37 .nl()38 .indentLines()39 .i()40 .block(function () {41 this.append(inspect(actual))42 .sp()43 .annotationBlock(function () {44 this.shouldEqualError(expected, inspect);45 if (comparison) {46 this.nl(2).append(comparison);47 }48 });49 })50 .nl()51 .outdentLines()52 .append(suffixOutput);53 }54 },55 });56 expect.addType({57 name: 'Symbol',58 identify(obj) {59 return typeof obj === 'symbol';60 },61 inspect(obj, depth, output, inspect) {62 return output63 .jsKeyword('Symbol')64 .text('(')65 .singleQuotedString(obj.toString().replace(/^Symbol\(|\)$/g, ''))66 .text(')');67 },68 });69 expect.addType({70 name: 'object',71 indent: true,72 forceMultipleLines: false,73 identify(obj) {74 return obj && typeof obj === 'object';75 },76 prefix(output, obj) {77 const constructor = obj.constructor;78 const constructorName =79 constructor &&80 typeof constructor === 'function' &&81 constructor !== Object &&82 utils.getFunctionName(constructor);83 if (constructorName && constructorName !== 'Object') {84 output.text(`${constructorName}(`);85 }86 return output.text('{');87 },88 property(output, key, inspectedValue, isArrayLike) {89 return output.propertyForObject(key, inspectedValue, isArrayLike);90 },91 suffix(output, obj) {92 output.text('}');93 const constructor = obj.constructor;94 const constructorName =95 constructor &&96 typeof constructor === 'function' &&97 constructor !== Object &&98 utils.getFunctionName(constructor);99 if (constructorName && constructorName !== 'Object') {100 output.text(')');101 }102 return output;103 },104 delimiter(output, i, length) {105 if (i < length - 1) {106 output.text(',');107 }108 return output;109 },110 getKeys: Object.getOwnPropertySymbols111 ? (obj) => {112 const keys = Object.getOwnPropertyNames(obj);113 const symbols = Object.getOwnPropertySymbols(obj);114 if (symbols.length > 0) {115 return keys.concat(symbols);116 } else {117 return keys;118 }119 }120 : Object.getOwnPropertyNames,121 // If Symbol support is not detected default to undefined which, when122 // passed to Array.prototype.sort, means "natural" (asciibetical) sort.123 keyComparator:124 typeof Symbol === 'function'125 ? (a, b) => {126 let aString = a;127 let bString = b;128 const aIsSymbol = typeof a === 'symbol';129 const bIsSymbol = typeof b === 'symbol';130 if (aIsSymbol) {131 if (bIsSymbol) {132 aString = a.toString();133 bString = b.toString();134 } else {135 return 1;136 }137 } else if (bIsSymbol) {138 return -1;139 }140 if (aString < bString) {141 return -1;142 } else if (aString > bString) {143 return 1;144 }145 return 0;146 }147 : undefined,148 equal(a, b, equal) {149 return utils.checkObjectEqualityUsingType(a, b, this, equal);150 },151 hasKey(obj, key, own) {152 if (own) {153 return Object.prototype.hasOwnProperty.call(obj, key);154 } else {155 return key in obj;156 }157 },158 inspect(obj, depth, output, inspect) {159 const keys = this.getKeys(obj);160 if (keys.length === 0) {161 this.prefix(output, obj);162 this.suffix(output, obj);163 return output;164 }165 const type = this;166 const inspectedItems = keys.map((key, index) => {167 const propertyDescriptor =168 Object.getOwnPropertyDescriptor &&169 Object.getOwnPropertyDescriptor(obj, key);170 const hasGetter = propertyDescriptor && propertyDescriptor.get;171 const hasSetter = propertyDescriptor && propertyDescriptor.set;172 const propertyOutput = output.clone();173 if (hasSetter && !hasGetter) {174 propertyOutput.text('set').sp();175 }176 // Inspect the setter function if there's no getter:177 let value;178 if (hasSetter && !hasGetter) {179 value = hasSetter;180 } else {181 value = type.valueForKey(obj, key);182 }183 let inspectedValue = inspect(value);184 if (value && value._expectIt) {185 inspectedValue = output.clone().block(inspectedValue);186 }187 type.property(propertyOutput, key, inspectedValue);188 propertyOutput.amend(189 type.delimiter(output.clone(), index, keys.length)190 );191 if (hasGetter && hasSetter) {192 propertyOutput.sp().jsComment('/* getter/setter */');193 } else if (hasGetter) {194 propertyOutput.sp().jsComment('/* getter */');195 }196 return propertyOutput;197 });198 const maxLineLength =199 output.preferredWidth - (depth === Infinity ? 0 : depth) * 2 - 2;200 let width = 0;201 const compact =202 inspectedItems.length > 5 ||203 inspectedItems.every((inspectedItem) => {204 if (inspectedItem.isMultiline()) {205 return false;206 }207 width += inspectedItem.size().width;208 return width < maxLineLength;209 });210 const itemsOutput = output.clone();211 if (compact) {212 let currentLineLength = 0;213 inspectedItems.forEach((inspectedItem, index) => {214 const size = inspectedItem.size();215 currentLineLength += size.width + 1;216 if (index > 0) {217 if (size.height === 1 && currentLineLength < maxLineLength) {218 itemsOutput.sp();219 } else {220 itemsOutput.nl();221 currentLineLength = size.width;222 }223 if (size.height > 1) {224 // Make sure that we don't append more to this line225 currentLineLength = maxLineLength;226 }227 }228 itemsOutput.append(inspectedItem);229 });230 } else {231 inspectedItems.forEach((inspectedItem, index) => {232 if (index > 0) {233 itemsOutput.nl();234 }235 itemsOutput.append(inspectedItem);236 });237 }238 const prefixOutput = this.prefix(output.clone(), obj);239 const suffixOutput = this.suffix(output.clone(), obj);240 output.append(prefixOutput);241 if (this.forceMultipleLines || itemsOutput.isMultiline()) {242 if (!prefixOutput.isEmpty()) {243 output.nl();244 }245 if (this.indent) {246 output.indentLines().i();247 }248 output.block(itemsOutput);249 if (this.indent) {250 output.outdentLines();251 }252 if (!suffixOutput.isEmpty()) {253 output.nl();254 }255 } else {256 output257 .sp(prefixOutput.isEmpty() ? 0 : 1)258 .append(itemsOutput)259 .sp(suffixOutput.isEmpty() ? 0 : 1);260 }261 return output.append(suffixOutput);262 },263 diff(actual, expected, output, diff, inspect, equal) {264 if (actual.constructor !== expected.constructor) {265 return output266 .text('Mismatching constructors ')267 .text(268 (actual.constructor && utils.getFunctionName(actual.constructor)) ||269 actual.constructor270 )271 .text(' should be ')272 .text(273 (expected.constructor &&274 utils.getFunctionName(expected.constructor)) ||275 expected.constructor276 );277 }278 output.inline = true;279 const actualKeys = this.getKeys(actual);280 const expectedKeys = this.getKeys(expected);281 const keys = this.uniqueKeys(actualKeys, expectedKeys);282 const prefixOutput = this.prefix(output.clone(), actual);283 output.append(prefixOutput).nl(prefixOutput.isEmpty() ? 0 : 1);284 if (this.indent) {285 output.indentLines();286 }287 const type = this;288 keys.forEach((key, index) => {289 output290 .nl(index > 0 ? 1 : 0)291 .i()292 .block(function () {293 const valueActual = type.valueForKey(actual, key);294 const valueExpected = type.valueForKey(expected, key);295 const annotation = output.clone();296 const conflicting = !equal(valueActual, valueExpected);297 let isInlineDiff = false;298 let valueOutput;299 if (conflicting) {300 if (!type.hasKey(expected, key)) {301 annotation.error('should be removed');302 isInlineDiff = true;303 } else if (!type.hasKey(actual, key)) {304 this.error('// missing').sp();305 valueOutput = output.clone().appendInspected(valueExpected);306 isInlineDiff = true;307 } else {308 const keyDiff = diff(valueActual, valueExpected);309 if (!keyDiff || (keyDiff && !keyDiff.inline)) {310 annotation.shouldEqualError(valueExpected);311 if (keyDiff) {312 annotation.nl(2).append(keyDiff);313 }314 } else {315 isInlineDiff = true;316 valueOutput = keyDiff;317 }318 }319 } else {320 isInlineDiff = true;321 }322 if (!valueOutput) {323 valueOutput = inspect(valueActual, conflicting ? Infinity : null);324 }325 valueOutput.amend(326 type.delimiter(output.clone(), index, actualKeys.length)327 );328 if (!isInlineDiff) {329 valueOutput = output.clone().block(valueOutput);330 }331 type.property(this, key, valueOutput);332 if (!annotation.isEmpty()) {333 this.sp().annotationBlock(annotation);334 }335 });336 });337 if (this.indent) {338 output.outdentLines();339 }340 const suffixOutput = this.suffix(output.clone(), actual);341 return output.nl(suffixOutput.isEmpty() ? 0 : 1).append(suffixOutput);342 },343 similar(a, b) {344 if (a === null || b === null) {345 return false;346 }347 const typeA = typeof a;348 const typeB = typeof b;349 if (typeA !== typeB) {350 return false;351 }352 if (typeA === 'string') {353 return ukkonen(a, b) < a.length / 2;354 }355 if (typeA !== 'object' || !a) {356 return false;357 }358 if (utils.isArray(a) && utils.isArray(b)) {359 return true;360 }361 const aKeys = this.getKeys(a);362 const bKeys = this.getKeys(b);363 let numberOfSimilarKeys = 0;364 const requiredSimilarKeys = Math.round(365 Math.max(aKeys.length, bKeys.length) / 2366 );367 return aKeys.concat(bKeys).some((key) => {368 if (this.hasKey(a, key) && this.hasKey(b, key)) {369 numberOfSimilarKeys += 1;370 }371 return numberOfSimilarKeys >= requiredSimilarKeys;372 });373 },374 uniqueKeys: utils.uniqueStringsAndSymbols,375 valueForKey(obj, key) {376 return obj[key];377 },378 });379 expect.addType({380 name: 'type',381 base: 'object',382 identify(value) {383 return value && value._unexpectedType;384 },385 inspect({ name }, depth, output) {386 return output.text('type: ').jsKeyword(name);387 },388 });389 expect.addType({390 name: 'array-like',391 base: 'object',392 identify: false,393 numericalPropertiesOnly: true,394 getKeys(obj) {395 const keys = new Array(obj.length);396 for (let i = 0; i < obj.length; i += 1) {397 keys[i] = i;398 }399 if (!this.numericalPropertiesOnly) {400 keys.push(...this.getKeysNonNumerical(obj));401 }402 return keys;403 },404 getKeysNonNumerical: Object.getOwnPropertySymbols405 ? (obj) => {406 const keys = [];407 Object.keys(obj).forEach((key) => {408 if (!utils.numericalRegExp.test(key)) {409 keys.push(key);410 }411 });412 const symbols = Object.getOwnPropertySymbols(obj);413 if (symbols.length > 0) {414 keys.push(...symbols);415 }416 return keys;417 }418 : (obj) => {419 const keys = [];420 Object.keys(obj).forEach((key) => {421 if (!utils.numericalRegExp.test(key)) {422 keys.push(key);423 }424 });425 return keys;426 },427 equal(a, b, equal) {428 if (a === b) {429 return true;430 } else if (a.constructor === b.constructor && a.length === b.length) {431 let i;432 // compare numerically indexed elements433 for (i = 0; i < a.length; i += 1) {434 if (!equal(this.valueForKey(a, i), this.valueForKey(b, i))) {435 return false;436 }437 }438 // compare non-numerical keys if enabled for the type439 if (!this.numericalPropertiesOnly) {440 const aKeys = this.getKeysNonNumerical(a).filter((key) => {441 // include keys whose value is not undefined442 return typeof this.valueForKey(a, key) !== 'undefined';443 });444 const bKeys = this.getKeysNonNumerical(b).filter((key) => {445 // include keys whose value is not undefined on either LHS or RHS446 return (447 typeof this.valueForKey(b, key) !== 'undefined' ||448 typeof this.valueForKey(a, key) !== 'undefined'449 );450 });451 if (aKeys.length !== bKeys.length) {452 return false;453 }454 for (i = 0; i < aKeys.length; i += 1) {455 if (456 !equal(457 this.valueForKey(a, aKeys[i]),458 this.valueForKey(b, bKeys[i])459 )460 ) {461 return false;462 }463 }464 }465 return true;466 } else {467 return false;468 }469 },470 prefix(output) {471 return output.text('[');472 },473 suffix(output) {474 return output.text(']');475 },476 inspect(arr, depth, output, inspect) {477 const prefixOutput = this.prefix(output.clone(), arr);478 const suffixOutput = this.suffix(output.clone(), arr);479 const keys = this.getKeys(arr);480 if (keys.length === 0) {481 return output.append(prefixOutput).append(suffixOutput);482 }483 if (depth === 1 && arr.length > 10) {484 return output.append(prefixOutput).text('...').append(suffixOutput);485 }486 const inspectedItems = keys.map((key) => {487 let inspectedValue;488 if (this.hasKey(arr, key)) {489 inspectedValue = inspect(this.valueForKey(arr, key));490 } else if (utils.numericalRegExp.test(key)) {491 // Sparse array entry492 inspectedValue = output.clone();493 } else {494 // Not present non-numerical property returned by getKeys495 inspectedValue = inspect(undefined);496 }497 return this.property(output.clone(), key, inspectedValue, true);498 });499 const currentDepth = defaultDepth - Math.min(defaultDepth, depth);500 const maxLineLength =501 output.preferredWidth - 20 - currentDepth * output.indentationWidth - 2;502 let width = 0;503 const multipleLines =504 this.forceMultipleLines ||505 inspectedItems.some((o) => {506 if (o.isMultiline()) {507 return true;508 }509 const size = o.size();510 width += size.width;511 return width > maxLineLength;512 });513 inspectedItems.forEach((inspectedItem, index) => {514 inspectedItem.amend(this.delimiter(output.clone(), index, keys.length));515 });516 if (multipleLines) {517 output.append(prefixOutput);518 if (!prefixOutput.isEmpty()) {519 output.nl();520 }521 if (this.indent) {522 output.indentLines();523 }524 inspectedItems.forEach((inspectedItem, index) => {525 output526 .nl(index > 0 ? 1 : 0)527 .i()528 .block(inspectedItem);529 });530 if (this.indent) {531 output.outdentLines();532 }533 if (!suffixOutput.isEmpty()) {534 output.nl();535 }536 return output.append(suffixOutput);537 } else {538 output.append(prefixOutput).sp(prefixOutput.isEmpty() ? 0 : 1);539 inspectedItems.forEach((inspectedItem, index) => {540 output.append(inspectedItem);541 const lastIndex = index === inspectedItems.length - 1;542 if (!lastIndex) {543 output.sp();544 }545 });546 return output.sp(suffixOutput.isEmpty() ? 0 : 1).append(suffixOutput);547 }548 },549 diffLimit: 512,550 diff(actual, expected, output, diff, inspect, equal) {551 output.inline = true;552 if (Math.max(actual.length, expected.length) > this.diffLimit) {553 output.jsComment(`Diff suppressed due to size > ${this.diffLimit}`);554 return output;555 }556 if (actual.constructor !== expected.constructor) {557 return this.baseType.diff(actual, expected, output);558 }559 const prefixOutput = this.prefix(output.clone(), actual);560 output.append(prefixOutput).nl(prefixOutput.isEmpty() ? 0 : 1);561 if (this.indent) {562 output.indentLines();563 }564 const actualElements = utils.duplicateArrayLikeUsingType(actual, this);565 const actualKeys = this.getKeys(actual);566 const expectedElements = utils.duplicateArrayLikeUsingType(567 expected,568 this569 );570 const expectedKeys = this.getKeys(expected);571 const nonNumericalKeysAndSymbols =572 !this.numericalPropertiesOnly &&573 utils.uniqueNonNumericalStringsAndSymbols(actualKeys, expectedKeys);574 const type = this;575 const changes = arrayChanges(576 actualElements,577 expectedElements,578 equal,579 (a, b) => type.similar(a, b),580 {581 includeNonNumericalProperties: nonNumericalKeysAndSymbols,582 }583 );584 const indexOfLastNonInsert = changes.reduce(585 (previousValue, diffItem, index) =>586 diffItem.type === 'insert' ? previousValue : index,587 -1588 );589 const packing = utils.packArrows(changes); // NOTE: Will have side effects in changes if the packing results in too many arrow lanes590 output.arrowsAlongsideChangeOutputs(591 packing,592 changes.map((diffItem, index) => {593 const delimiterOutput = type.delimiter(594 output.clone(),595 index,596 indexOfLastNonInsert + 1597 );598 if (diffItem.type === 'moveTarget') {599 return output.clone();600 } else {601 return output.clone().block(function () {602 if (diffItem.type === 'moveSource') {603 const propertyOutput = type.property(604 output.clone(),605 diffItem.actualIndex,606 inspect(diffItem.value),607 true608 );609 this.amend(propertyOutput)610 .amend(delimiterOutput)611 .sp()612 .error('// should be moved');613 } else if (diffItem.type === 'insert') {614 this.annotationBlock(function () {615 this.error('missing ').block(function () {616 const index =617 typeof diffItem.actualIndex !== 'undefined'618 ? diffItem.actualIndex619 : diffItem.expectedIndex;620 const propertyOutput = type.property(621 output.clone(),622 index,623 inspect(diffItem.value),624 true625 );626 this.amend(propertyOutput);627 });628 });629 } else if (diffItem.type === 'remove') {630 this.block(function () {631 const propertyOutput = type.property(632 output.clone(),633 diffItem.actualIndex,634 inspect(diffItem.value),635 true636 );637 this.amend(propertyOutput)638 .amend(delimiterOutput)639 .sp()640 .error('// should be removed');641 });642 } else if (diffItem.type === 'equal') {643 this.block(function () {644 const propertyOutput = type.property(645 output.clone(),646 diffItem.actualIndex,647 inspect(diffItem.value),648 true649 );650 this.amend(propertyOutput).amend(delimiterOutput);651 });652 } else {653 this.block(function () {654 const valueDiff = diff(diffItem.value, diffItem.expected);655 if (valueDiff && valueDiff.inline) {656 this.append(valueDiff).append(delimiterOutput);657 } else {658 const propertyOutput = type.property(659 output.clone(),660 diffItem.actualIndex,661 inspect(diffItem.value),662 true663 );664 this.append(propertyOutput)665 .append(delimiterOutput)666 .sp()667 .annotationBlock(function () {668 this.shouldEqualError(diffItem.expected, inspect);669 if (valueDiff) {670 this.nl(2).append(valueDiff);671 }672 });673 }674 });675 }676 });677 }678 })679 );680 if (this.indent) {681 output.outdentLines();682 }683 const suffixOutput = this.suffix(output.clone(), actual);684 return output.nl(suffixOutput.isEmpty() ? 0 : 1).append(suffixOutput);685 },686 });687 expect.addType({688 name: 'array',689 base: 'array-like',690 numericalPropertiesOnly: false,691 identify(arr) {692 return utils.isArray(arr);693 },694 });695 expect.addType({696 name: 'arguments',697 base: 'array-like',698 prefix(output) {699 return output.text('arguments(', 'cyan');700 },701 suffix(output) {702 return output.text(')', 'cyan');703 },704 identify(obj) {705 return Object.prototype.toString.call(obj) === '[object Arguments]';706 },707 });708 const errorMethodBlacklist = [709 'message',710 'name',711 'description',712 'line',713 'number',714 'column',715 'sourceId',716 'sourceURL',717 'stack',718 'stackArray',719 '__stackCleaned__',720 'isOperational', // added by the promise implementation,721 '__callSiteEvals', // attached by deno722 ].reduce((result, prop) => {723 result[prop] = true;724 return result;725 }, {});726 if (Object.prototype.hasOwnProperty.call(new Error(), 'arguments')) {727 // node.js 0.10 adds two extra non-enumerable properties to Error instances:728 errorMethodBlacklist.arguments = true;729 errorMethodBlacklist.type = true;730 }731 expect.addType({732 base: 'object',733 name: 'Error',734 identify(value) {735 return utils.isError(value);736 },737 getKeys(value) {738 const keys = this.baseType739 .getKeys(value)740 .filter((key) => !errorMethodBlacklist[key]);741 keys.unshift('message');742 return keys;743 },744 unwrap(value) {745 return this.getKeys(value).reduce((result, key) => {746 result[key] = value[key];747 return result;748 }, {});749 },750 equal(a, b, equal) {751 return (752 a === b ||753 (equal(a.message, b.message) &&754 utils.checkObjectEqualityUsingType(a, b, this, equal))755 );756 },757 inspect(value, depth, output, inspect) {758 output.errorName(value).text('(');759 const keys = this.getKeys(value);760 if (keys.length === 1 && keys[0] === 'message') {761 if (value.message !== '') {762 output.append(inspect(value.message));763 }764 } else {765 output.append(inspect(this.unwrap(value), depth));766 }767 return output.text(')');768 },769 diff(actual, expected, output, diff) {770 if (actual.constructor !== expected.constructor) {771 return output772 .text('Mismatching constructors ')773 .errorName(actual)774 .text(' should be ')775 .errorName(expected);776 }777 output = diff(this.unwrap(actual), this.unwrap(expected));778 if (output) {779 output = output780 .clone()781 .errorName(actual)782 .text('(')783 .append(output)784 .text(')');785 output.inline = false;786 }787 return output;788 },789 });790 const unexpectedErrorMethodBlacklist = [791 'output',792 '_isUnexpected',793 'htmlMessage',794 '_hasSerializedErrorMessage',795 'expect',796 'assertion',797 'originalError',798 ].reduce((result, prop) => {799 result[prop] = true;800 return result;801 }, {});802 expect.addType({803 base: 'Error',804 name: 'UnexpectedError',805 identify(value) {806 return (807 value &&808 typeof value === 'object' &&809 value._isUnexpected &&810 this.baseType.identify(value)811 );812 },813 getKeys(value) {814 return this.baseType815 .getKeys(value)816 .filter((key) => !unexpectedErrorMethodBlacklist[key]);817 },818 inspect(value, depth, output) {819 output.jsFunctionName(this.name).text('(');820 const errorMessage = value.getErrorMessage(output);821 if (errorMessage.isMultiline()) {822 output.nl().indentLines().i().block(errorMessage).nl();823 } else {824 output.append(errorMessage);825 }826 return output.text(')');827 },828 });829 expect.addType({830 name: 'date',831 identify(obj) {832 return Object.prototype.toString.call(obj) === '[object Date]';833 },834 equal(a, b) {835 return a.getTime() === b.getTime();836 },837 inspect(date, depth, output, inspect) {838 // TODO: Inspect "new" as an operator and Date as a built-in once we have the styles defined:839 return output840 .jsKeyword('new')841 .sp()842 .text('Date(')843 .append(inspect(date.toISOString().replace(/\.000Z$/, 'Z')).text(')'));844 },845 });846 expect.addType({847 base: 'object',848 name: 'function',849 identify(f) {850 return typeof f === 'function';851 },852 getKeys: Object.keys,853 equal(a, b) {854 return a === b;855 },856 inspect(f, depth, output, inspect) {857 // Don't break when a function has its own custom #toString:858 const source = Function.prototype.toString859 .call(f)860 .replace(/\r\n?|\n\r?/g, '\n');861 let name = utils.getFunctionName(f) || '';862 let preamble;863 let body;864 let bodyIndent;865 const matchSource = source.match(866 /^\s*((?:async )?\s*(?:\S+\s*=>|\([^)]*\)\s*=>|class|function\s?(?:\*\s*)?\w*\s*\([^)]*\)))([\s\S]*)$/867 );868 if (matchSource) {869 // Normalize so there's always space after "function" and never after "*" for generator functions:870 preamble = matchSource[1]871 .replace(/function(\S)/, 'function $1')872 .replace(/\* /, '*');873 if (preamble === 'function ()' && name) {874 // fn.bind() doesn't seem to include the name in the .toString() output:875 preamble = `function ${name}()`;876 }877 body = matchSource[2];878 let matchBodyAndIndent = body.match(/^(\s*\{)([\s\S]*?)([ ]*)\}\s*$/);879 let openingBrace;880 let isWrappedInBraces = true;881 let closingBrace = '}';882 let reindentBodyLevel = 0;883 if (matchBodyAndIndent) {884 openingBrace = matchBodyAndIndent[1];885 body = matchBodyAndIndent[2];886 bodyIndent = matchBodyAndIndent[3] || '';887 if (bodyIndent.length === 1) {888 closingBrace = ' }';889 }890 } else {891 // Attempt to match an arrow function with an implicit return body.892 matchBodyAndIndent = body.match(/^(\s*)([\s\S]*?)([ ]*)\s*$/);893 if (matchBodyAndIndent) {894 openingBrace = matchBodyAndIndent[1];895 isWrappedInBraces = false;896 body = matchBodyAndIndent[2];897 const matchInitialNewline = openingBrace.match(/^\n( +)/);898 if (matchInitialNewline) {899 openingBrace = '\n';900 if (/\n/.test(body)) {901 // An arrow function whose body starts with a newline, as prettier likes to output, eg.:902 // () =>903 // foo(904 // 1905 // );906 // Shuffle/hack things around so it will be formatted correctly:907 bodyIndent = matchInitialNewline[1];908 reindentBodyLevel = 1;909 } else {910 body = body.replace(/^\s*/, ' ');911 }912 } else {913 bodyIndent = matchBodyAndIndent[3] || '';914 }915 closingBrace = '';916 }917 }918 // Remove leading indentation unless the function is a one-liner or it uses multiline string literals919 if (/\n/.test(body) && !/\\\n/.test(body)) {920 body = body.replace(new RegExp(`^ {${bodyIndent.length}}`, 'mg'), '');921 const indent = detectIndent(body);922 body = body.replace(923 new RegExp(`^(?:${indent.indent})*`, 'mg'),924 ({ length }) =>925 utils.leftPad(926 '',927 (length / indent.amount + reindentBodyLevel) *928 output.indentationWidth,929 ' '930 )931 );932 }933 if (!name || name === 'anonymous') {934 name = '';935 }936 if (/^\s*\[native code\]\s*$/.test(body)) {937 body = ' /* native code */ ';938 closingBrace = '}';939 } else if (/^\s*$/.test(body)) {940 body = '';941 } else if (942 /^\s*[^\r\n]{1,30}\s*$/.test(body) &&943 body.indexOf('//') === -1 &&944 isWrappedInBraces945 ) {946 body = ` ${body.trim()} `;947 closingBrace = '}';948 } else {949 body = body.replace(950 /^((?:.*\n){3}( *).*\n)[\s\S]*?\n[\s\S]*?\n((?:.*\n){3})$/,951 '$1$2// ... lines removed ...\n$3'952 );953 }954 if (matchBodyAndIndent) {955 body = openingBrace + body + closingBrace;956 } else {957 // Strip trailing space from arrow function body958 body = body.replace(/[ ]*$/, '');959 }960 } else {961 preamble = `function ${name}( /*...*/ ) `;962 body = '{ /*...*/ }';963 }964 return output.code(preamble + body, 'javascript');965 },966 diff(actual, expected, output) {967 // Avoid rendering an object diff when both are functions968 if (typeof actual !== 'function' || typeof expected !== 'function') {969 return this.baseType.diff(actual, expected, output);970 }971 },972 });973 expect.addType({974 name: 'Set',975 base: 'object',976 indent: true,977 identify(obj) {978 return obj instanceof Set;979 },980 equal(a, b, equal) {981 if (a.size !== b.size) {982 return false;983 }984 let unequal = false;985 a.forEach((value) => {986 unequal = unequal || !b.has(value);987 });988 if (unequal) {989 // Slow path990 const bElements = [];991 b.forEach((element) => {992 bElements.push(element);993 });994 unequal = false;995 a.forEach((value) => {996 unequal =997 unequal ||998 (!b.has(value) &&999 !bElements.some((bElement) => equal(value, bElement)));1000 });1001 }1002 return !unequal;1003 },1004 prefix(output) {1005 return output.jsKeyword('new').sp().jsKeyword('Set').text('([');1006 },1007 suffix(output) {1008 return output.text('])');1009 },1010 inspect(set, depth, output, inspect) {1011 // Mostly copied from array-like's inspect:1012 const prefixOutput = this.prefix(output.clone(), set);1013 const suffixOutput = this.suffix(output.clone(), set);1014 if (set.size === 0) {1015 return output.append(prefixOutput).append(suffixOutput);1016 }1017 if (depth === 1 && set.size > 10) {1018 return output.append(prefixOutput).text('...').append(suffixOutput);1019 }1020 const inspectedItems = [];1021 set.forEach((item) => {1022 inspectedItems.push(inspect(item));1023 });1024 const currentDepth = defaultDepth - Math.min(defaultDepth, depth);1025 const maxLineLength =1026 output.preferredWidth - 20 - currentDepth * output.indentationWidth - 2;1027 let width = 0;1028 const multipleLines = inspectedItems.some((o) => {1029 if (o.isMultiline()) {1030 return true;1031 }1032 const size = o.size();1033 width += size.width;1034 return width > maxLineLength;1035 });1036 const type = this;1037 inspectedItems.forEach((inspectedItem, index) => {1038 inspectedItem.amend(1039 type.delimiter(output.clone(), index, inspectedItems.length)1040 );1041 });1042 output.append(prefixOutput);1043 if (this.forceMultipleLines || multipleLines) {1044 if (!prefixOutput.isEmpty()) {1045 output.nl();1046 }1047 if (this.indent) {1048 output.indentLines();1049 }1050 inspectedItems.forEach((inspectedItem, index) => {1051 output1052 .nl(index > 0 ? 1 : 0)1053 .i()1054 .block(inspectedItem);1055 });1056 if (this.indent) {1057 output.outdentLines();1058 }1059 if (!suffixOutput.isEmpty()) {1060 output.nl();1061 }1062 } else {1063 output.sp(prefixOutput.isEmpty() ? 0 : 1);1064 inspectedItems.forEach((inspectedItem, index) => {1065 output.append(inspectedItem);1066 const lastIndex = index === inspectedItems.length - 1;1067 if (!lastIndex) {1068 output.sp();1069 }1070 });1071 output.sp(suffixOutput.isEmpty() ? 0 : 1);1072 }1073 output.append(suffixOutput);1074 },1075 diff(actual, expected, output, diff, inspect, equal) {1076 output.inline = true;1077 const prefixOutput = this.prefix(output.clone(), actual);1078 const suffixOutput = this.suffix(output.clone(), actual);1079 output.append(prefixOutput).nl(prefixOutput.isEmpty() ? 0 : 1);1080 if (this.indent) {1081 output.indentLines();1082 }1083 const type = this;1084 let index = 0;1085 const actualElements = [];1086 actual.forEach((element) => {1087 actualElements.push(element);1088 });1089 const expectedElements = [];1090 expected.forEach((element) => {1091 expectedElements.push(element);1092 });1093 actual.forEach((actualElement) => {1094 output1095 .nl(index > 0 ? 1 : 0)1096 .i()1097 .block(function () {1098 this.appendInspected(actualElement);1099 type.delimiter(this, index, actual.size);1100 if (1101 !expected.has(actualElement) &&1102 !expectedElements.some((element) => equal(element, actualElement))1103 ) {1104 this.sp().annotationBlock(function () {1105 this.error('should be removed');1106 });1107 }1108 });1109 index += 1;1110 });1111 expected.forEach((expectedElement) => {1112 if (1113 !actual.has(expectedElement) &&1114 !actualElements.some((element) => equal(element, expectedElement))1115 ) {1116 output1117 .nl(index > 0 ? 1 : 0)1118 .i()1119 .annotationBlock(function () {1120 this.error('missing').sp().appendInspected(expectedElement);1121 });1122 index += 1;1123 }1124 });1125 if (this.indent) {1126 output.outdentLines();1127 }1128 output.nl(suffixOutput.isEmpty() ? 0 : 1).append(suffixOutput);1129 return output;1130 },1131 });1132 expect.addType({1133 base: 'function',1134 name: 'expect.it',1135 identify(f) {1136 return typeof f === 'function' && f._expectIt;1137 },1138 inspect({ _expectations, _OR }, depth, output, inspect) {1139 output.text('expect.it(');1140 let orBranch = false;1141 _expectations.forEach((expectation, index) => {1142 if (expectation === _OR) {1143 orBranch = true;1144 return;1145 }1146 if (orBranch) {1147 output.text(')\n .or(');1148 } else if (index > 0) {1149 output.text(')\n .and(');1150 }1151 const args = Array.prototype.slice.call(expectation);1152 args.forEach((arg, i) => {1153 if (i > 0) {1154 output.text(', ');1155 }1156 output.append(inspect(arg));1157 });1158 orBranch = false;1159 });1160 return output.amend(')');1161 },1162 });1163 expect.addType({1164 name: 'Promise',1165 base: 'object',1166 identify(obj) {1167 return (1168 obj && this.baseType.identify(obj) && typeof obj.then === 'function'1169 );1170 },1171 inspect(promise, depth, output, inspect) {1172 output.jsFunctionName('Promise');1173 if (promise.isPending && promise.isPending()) {1174 output.sp().yellow('(pending)');1175 } else if (promise.isFulfilled && promise.isFulfilled()) {1176 output.sp().green('(fulfilled)');1177 if (promise.value) {1178 const value = promise.value();1179 if (typeof value !== 'undefined') {1180 output.sp().text('=>').sp().append(inspect(value));1181 }1182 }1183 } else if (promise.isRejected && promise.isRejected()) {1184 output.sp().red('(rejected)');1185 const reason = promise.reason();1186 if (typeof reason !== 'undefined') {1187 output.sp().text('=>').sp().append(inspect(promise.reason()));1188 }1189 }1190 return output;1191 },1192 });1193 expect.addType({1194 name: 'regexp',1195 base: 'object',1196 identify: isRegExp,1197 equal(a, b) {1198 return (1199 a === b ||1200 (a.source === b.source &&1201 a.global === b.global &&1202 a.ignoreCase === b.ignoreCase &&1203 a.multiline === b.multiline)1204 );1205 },1206 inspect(regExp, depth, output) {1207 return output.jsRegexp(regExp);1208 },1209 diff(actual, expected, output, diff, inspect) {1210 output.inline = false;1211 return output.stringDiff(String(actual), String(expected), {1212 type: 'Chars',1213 markUpSpecialCharacters: true,1214 });1215 },1216 });1217 expect.addType({1218 name: 'binaryArray',1219 base: 'array-like',1220 digitWidth: 2,1221 hexDumpWidth: 16,1222 identify: false,1223 prefix(output) {1224 return output.code(`${this.name}([`, 'javascript');1225 },1226 suffix(output) {1227 return output.code('])', 'javascript');1228 },1229 equal(a, b) {1230 if (a === b) {1231 return true;1232 }1233 if (a.length !== b.length) {1234 return false;1235 }1236 for (let i = 0; i < a.length; i += 1) {1237 if (a[i] !== b[i]) {1238 return false;1239 }1240 }1241 return true;1242 },1243 hexDump(obj, maxLength) {1244 let hexDump = '';1245 if (typeof maxLength !== 'number' || maxLength === 0) {1246 maxLength = obj.length;1247 }1248 for (let i = 0; i < maxLength; i += this.hexDumpWidth) {1249 if (hexDump.length > 0) {1250 hexDump += '\n';1251 }1252 let hexChars = '';1253 let asciiChars = ' │';1254 for (let j = 0; j < this.hexDumpWidth; j += 1) {1255 if (i + j < maxLength) {1256 const octet = obj[i + j];1257 hexChars += `${leftPad(1258 octet.toString(16).toUpperCase(),1259 this.digitWidth,1260 '0'1261 )} `;1262 asciiChars += String.fromCharCode(octet)1263 .replace(/\n/g, '␊')1264 .replace(/\r/g, '␍');1265 } else if (this.digitWidth === 2) {1266 hexChars += ' ';1267 }1268 }1269 if (this.digitWidth === 2) {1270 hexDump += `${hexChars + asciiChars}│`;1271 } else {1272 hexDump += hexChars.replace(/\s+$/, '');1273 }1274 }1275 return hexDump;1276 },1277 inspect(obj, depth, output) {1278 this.prefix(output, obj);1279 let codeStr = '';1280 for (let i = 0; i < Math.min(this.hexDumpWidth, obj.length); i += 1) {1281 if (i > 0) {1282 codeStr += ', ';1283 }1284 const octet = obj[i];1285 codeStr += `0x${leftPad(1286 octet.toString(16).toUpperCase(),1287 this.digitWidth,1288 '0'1289 )}`;1290 }1291 if (obj.length > this.hexDumpWidth) {1292 codeStr += ` /* ${obj.length - this.hexDumpWidth} more */ `;1293 }1294 output.code(codeStr, 'javascript');1295 this.suffix(output, obj);1296 return output;1297 },1298 diffLimit: 512,1299 diff(actual, expected, output, diff, inspect) {1300 output.inline = false;1301 if (Math.max(actual.length, expected.length) > this.diffLimit) {1302 output.jsComment(`Diff suppressed due to size > ${this.diffLimit}`);1303 } else {1304 output1305 .stringDiff(this.hexDump(actual), this.hexDump(expected), {1306 type: 'Chars',1307 markUpSpecialCharacters: false,1308 })1309 // eslint-disable-next-line no-control-regex1310 .replaceText(/[\x00-\x1f\x7f-\xff␊␍]/g, '.')1311 .replaceText(/[│ ]/g, function (styles, content) {1312 this.text(content);1313 });1314 }1315 return output;1316 },1317 });1318 [8, 16, 32].forEach(function (numBits) {1319 ['Int', 'Uint'].forEach((intOrUint) => {1320 const constructorName = `${intOrUint + numBits}Array`;1321 const Constructor = global[constructorName];1322 expect.addType({1323 name: constructorName,1324 base: 'binaryArray',1325 hexDumpWidth: 128 / numBits,1326 digitWidth: numBits / 4,1327 identify:1328 Constructor !== 'undefined' &&1329 function (obj) {1330 return obj instanceof Constructor;1331 },1332 });1333 }, this);1334 }, this);1335 expect.addType({1336 name: 'Buffer',1337 base: 'binaryArray',1338 identify: typeof Buffer === 'function' && Buffer.isBuffer,1339 prefix(output) {1340 return output.code(`Buffer.from([`, 'javascript');1341 },1342 });1343 expect.addType({1344 name: 'string',1345 identify(value) {1346 return typeof value === 'string';1347 },1348 inspect(value, depth, output) {1349 return output.singleQuotedString(value);1350 },1351 diffLimit: 65536,1352 diff(actual, expected, output, diff, inspect) {1353 if (Math.max(actual.length, expected.length) > this.diffLimit) {1354 output.jsComment(`Diff suppressed due to size > ${this.diffLimit}`);1355 return output;1356 }1357 output.stringDiff(actual, expected, {1358 type: 'WordsWithSpace',1359 markUpSpecialCharacters: true,1360 });1361 output.inline = false;1362 return output;1363 },1364 });1365 expect.addType({1366 name: 'number',1367 identify(value) {1368 return typeof value === 'number' && !isNaN(value);1369 },1370 inspect(value, depth, output) {1371 if (value === 0 && 1 / value === -Infinity) {1372 value = '-0';1373 } else {1374 value = String(value);1375 }1376 return output.jsNumber(String(value));1377 },1378 });1379 expect.addType({1380 name: 'NaN',1381 identify(value) {1382 return typeof value === 'number' && isNaN(value);1383 },1384 inspect(value, depth, output) {1385 return output.jsPrimitive(value);1386 },1387 });1388 expect.addType({1389 name: 'BigInt',1390 identify(value) {1391 return typeof value === 'bigint';1392 },1393 inspect(value, depth, output) {1394 return output.jsNumber(value.toString()).code('n', 'javascript');1395 },1396 });1397 expect.addType({1398 name: 'boolean',1399 identify(value) {1400 return typeof value === 'boolean';1401 },1402 inspect(value, depth, output) {1403 return output.jsPrimitive(value);1404 },1405 });1406 expect.addType({1407 name: 'undefined',1408 identify(value) {1409 return typeof value === 'undefined';1410 },1411 inspect(value, depth, output) {1412 return output.jsPrimitive(value);1413 },1414 });1415 expect.addType({1416 name: 'null',1417 identify(value) {1418 return value === null;1419 },1420 inspect(value, depth, output) {1421 return output.jsPrimitive(value);1422 },1423 });1424 expect.addType({1425 name: 'assertion',1426 identify(value) {1427 return value instanceof AssertionString;1428 },1429 });...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

...194 }195 }196 return target;197 },198 uniqueStringsAndSymbols(...args) {199 // [filterFn], item1, item2...200 let filterFn;201 if (typeof args[0] === 'function') {202 filterFn = args[0];203 }204 const index = {};205 const uniqueStringsAndSymbols = [];206 function visit(item) {207 if (Array.isArray(item)) {208 item.forEach(visit);209 } else if (210 !Object.prototype.hasOwnProperty.call(index, item) &&211 (!filterFn || filterFn(item))212 ) {213 index[item] = true;214 uniqueStringsAndSymbols.push(item);215 }216 }217 for (let i = filterFn ? 1 : 0; i < args.length; i += 1) {218 visit(args[i]);219 }220 return uniqueStringsAndSymbols;221 },222 uniqueNonNumericalStringsAndSymbols(...args) {223 // ...224 return utils.uniqueStringsAndSymbols(225 (stringOrSymbol) =>226 typeof stringOrSymbol === 'symbol' ||227 !utils.numericalRegExp.test(stringOrSymbol),228 Array.prototype.slice.call(args)229 );230 },231 forwardFlags(testDescriptionString, flags) {232 return testDescriptionString233 .replace(/\[(!?)([^\]]+)\] ?/g, (match, negate, flag) =>234 Boolean(flags[flag]) !== Boolean(negate) ? `${flag} ` : ''235 )236 .trim();237 },238 numericalRegExp: /^(?:0|[1-9][0-9]*)$/,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { uniqueStringsAndSymbols } from 'unexpected-htmllike';2expect.addAssertion('<any> to have unique strings and symbols', function (expect, subject) {3 return expect(uniqueStringsAndSymbols(subject), 'to be empty');4});5import { uniqueStringsAndSymbols } from 'unexpected-htmllike';6expect.addAssertion('<any> to have unique strings and symbols', function (expect, subject) {7 return expect(uniqueStringsAndSymbols(subject), 'to be empty');8});9import { uniqueStringsAndSymbols } from 'unexpected-htmllike';10expect.addAssertion('<any> to have unique strings and symbols', function (expect, subject) {11 return expect(uniqueStringsAndSymbols(subject), 'to be empty');12});13import { uniqueStringsAndSymbols } from 'unexpected-htmllike';14expect.addAssertion('<any> to have unique strings and symbols', function (expect, subject) {15 return expect(uniqueStringsAndSymbols(subject), 'to be empty');16});17import { uniqueStringsAndSymbols } from 'unexpected-htmllike';18expect.addAssertion('<any> to have unique strings and symbols', function (expect, subject) {19 return expect(uniqueStringsAndSymbols(subject), 'to be empty');20});21import { uniqueStringsAndSymbols } from 'unexpected-htmllike';22expect.addAssertion('<any> to have unique strings and symbols', function (expect, subject) {23 return expect(uniqueStringsAndSymbols(subject

Full Screen

Using AI Code Generation

copy

Full Screen

1const {uniqueStringsAndSymbols} = require('unexpected');2const unexpected = require('unexpected');3const unexpectedHtmllike = require('unexpected-htmllike');4const unexpectedDom = require('unexpected-dom');5const unexpectedSinon = require('unexpected-sinon');6const unexpectedReact = require('unexpected-react');7const unexpectedEnzyme = require('unexpected-enzyme');8const unexpectedResemble = require('unexpected-resemble');9const unexpectedMoment = require('unexpected-moment');10const unexpectedKnex = require('unexpected-knex');11const unexpectedCheck = require('unexpected-che

Full Screen

Using AI Code Generation

copy

Full Screen

1const unexpected = require('unexpected');2const unexpectedHtmllike = require('unexpected-htmllike');3const expect = unexpected.clone().use(unexpectedHtmllike);4const unexpected = require('unexpected');5const unexpectedHtmllike = require('unexpected-htmllike');6const expect = unexpected.clone().use(unexpectedHtmllike);7const unexpected = require('unexpected');8const unexpectedHtmllike = require('unexpected-htmllike');9const expect = unexpected.clone().use(unexpectedHtmllike);10const unexpected = require('unexpected');11const unexpectedHtmllike = require('unexpected-htmllike');12const expect = unexpected.clone().use(unexpectedHtmllike);13const unexpected = require('unexpected');14const unexpectedHtmllike = require('unexpected-htmllike');15const expect = unexpected.clone().use(unexpectedHtmllike);16const unexpected = require('unexpected');17const unexpectedHtmllike = require('unexpected-htmllike');18const expect = unexpected.clone().use(unexpectedHtmllike);19const unexpected = require('unexpected');20const unexpectedHtmllike = require('unexpected-htmllike');21const expect = unexpected.clone().use(unexpectedHtmllike);22const unexpected = require('unexpected');23const unexpectedHtmllike = require('unexpected-htmllike');24const expect = unexpected.clone().use(unexpectedHtmllike);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { uniqueStringsAndSymbols } = require('unexpected');2const expect = require('unexpected').clone();3const unexpectedSet = require('unexpected-set');4expect.installPlugin(unexpectedSet);5const unexpectedSorted = require('unexpected-sorted');6expect.installPlugin(unexpectedSorted);7const unexpectedDom = require('unexpected-dom');8expect.installPlugin(unexpectedDom);9const unexpectedReact = require('unexpected-react');10expect.installPlugin(unexpectedReact);11const unexpectedMarkdown = require('unexpected-markdown');12expect.installPlugin(unexpectedMarkdown);13const unexpectedMoment = require('unexpected-moment');14expect.installPlugin(unexpectedMoment);15const unexpectedSinon = require('unexpected-sinon');16expect.installPlugin(unexpectedSinon);17const unexpectedHtmlLike = require('unexpected-htmllike');18expect.installPlugin(unexpectedHtmlLike);19const unexpectedRedux = require('unexpected-redux');20expect.installPlugin(unexpectedRedux);21const unexpectedImmutable = require('unexpected-immutable');22expect.installPlugin(unexpectedImmutable);23const unexpectedEventEmitter = require('unexpected-eventemitter');24expect.installPlugin(unexpectedEventEmitter);25const unexpectedKnockout = require('unexpected-knockout');26expect.installPlugin(unexpectedKnockout);27const unexpectedJquery = require('unexpected-jquery');28expect.installPlugin(unexpectedJquery);29const unexpectedMithril = require('unexpected-mithril');30expect.installPlugin(unexpectedMithril);31const unexpectedRamda = require('unexpected-ramda');32expect.installPlugin(unexpectedRamda);33const unexpectedRx = require('unexpected-rx');34expect.installPlugin(unexpectedRx);

Full Screen

Using AI Code Generation

copy

Full Screen

1const unexpectedString = require('unexpected-string');2const str = "This is a string";3const result = unexpectedString.uniqueStringsAndSymbols(str);4console.log(result);5const unexpectedString = require('unexpected-string');6const str = "This is a string";7const result = unexpectedString.uniqueStringsAndSymbols(str);8console.log(result);9const unexpectedString = require('unexpected-string');10const str = "This is a string";11const result = unexpectedString.uniqueStringsAndSymbols(str);12console.log(result);13const unexpectedString = require('unexpected-string');14const str = "This is a string";15const result = unexpectedString.uniqueStringsAndSymbols(str);16console.log(result);17const unexpectedString = require('unexpected-string');18const str = "This is a string";19const result = unexpectedString.uniqueStringsAndSymbols(str);20console.log(result);21const unexpectedString = require('unexpected-string');22const str = "This is a string";23const result = unexpectedString.uniqueStringsAndSymbols(str);24console.log(result);25const unexpectedString = require('unexpected-string');26const str = "This is a string";27const result = unexpectedString.uniqueStringsAndSymbols(str);28console.log(result);29const unexpectedString = require('unexpected-string');30const str = "This is a string";31const result = unexpectedString.uniqueStringsAndSymbols(str);32console.log(result);33const unexpectedString = require('unexpected-string');34const str = "This is a string";35const result = unexpectedString.uniqueStringsAndSymbols(str);36console.log(result);37const unexpectedString = require('unexpected-string');38const str = "This is a string";39const result = unexpectedString.uniqueStringsAndSymbols(str);40console.log(result);41const unexpectedString = require('unexpected-string');42const str = "This is a string";

Full Screen

Using AI Code Generation

copy

Full Screen

1const { uniqueStringsAndSymbols } = require('unexpected');2describe('uniqueStringsAndSymbols', () => {3 it('should return true for a unique string', () => {4 expect(uniqueStringsAndSymbols('unique'), 'to be true');5 });6 it('should return false for a non unique string', () => {7 expect(uniqueStringsAndSymbols('nonunique'), 'to be false');8 });9});10const { uniqueStringsAndSymbols } = require('unexpected');11describe('uniqueStringsAndSymbols', () => {12 it('should return true for a unique string', () => {13 expect(uniqueStringsAndSymbols('unique'), 'to be true');14 });15 it('should return false for a non unique string', () => {16 expect(uniqueStringsAndSymbols('nonunique'), 'to be false');17 });18});19const { uniqueStringsAndSymbols } = require('unexpected');20describe('uniqueStringsAndSymbols', () => {21 it('should return true for a unique string', () => {22 expect(uniqueStringsAndSymbols('unique'), 'to be true');23 });24 it('should return false for a non unique string', () => {25 expect(uniqueStringsAndSymbols('nonunique'), 'to be false');26 });27});28const { uniqueStringsAndSymbols } = require('unexpected');29describe('uniqueStringsAndSymbols', () => {30 it('should return true for a unique string', () => {31 expect(uniqueStringsAndSymbols('unique'), 'to be true');32 });33 it('should return false for a non unique string', () => {34 expect(uniqueStringsAndSymbols('nonunique'), 'to be false');35 });36});37const { uniqueStringsAndSymbols } = require('unexpected');38describe('uniqueStringsAndSymbols', () => {39 it('should return true for a unique string', () => {40 expect(uniqueStringsAnd

Full Screen

Using AI Code Generation

copy

Full Screen

1const { expect, createSpy, restoreSpies } = require('unexpected');2const unexpectedString = require('unexpected-string');3const unexpected = expect.clone().use(unexpectedString);4const testString = 'Hello World!';5unexpected(testString, 'to have unique strings and symbols');6unexpected(testString, 'not to have unique strings and symbols');7const spy = createSpy(() => {});8spy(testString);9unexpected(spy, 'was called with', 'to have unique strings and symbols');10restoreSpies();11const { expect, createSpy, restoreSpies } = require('unexpected');12const unexpectedString = require('unexpected-string');13const unexpected = expect.clone().use(unexpectedString);14const testString = 'Hello World!';15unexpected(testString, 'to have unique strings and symbols');16unexpected(testString, 'not to have unique strings and symbols');17const spy = createSpy(() => {});18spy(testString);19unexpected(spy, 'was called with', 'to have unique strings and symbols');20restoreSpies();21const { expect, createSpy, restoreSpies } = require('unexpected');22const unexpectedString = require('unexpected-string');23const unexpected = expect.clone().use(unexpectedString);24const testString = 'Hello World!';25unexpected(testString, 'to have unique strings and symbols');26unexpected(testString, 'not to have unique strings and symbols');27const spy = createSpy(() => {});28spy(testString);29unexpected(spy, 'was called with', 'to have unique strings and symbols');30restoreSpies();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

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

Run unexpected automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful