Best JavaScript code snippet using jest
deep_cyclic_copy.js
Source:deep_cyclic_copy.js
...30 return value;31 } else if (cycles.has(value)) {32 return cycles.get(value);33 } else if (Array.isArray(value)) {34 return deepCyclicCopyArray(value, options, cycles);35 } else {36 return deepCyclicCopyObject(value, options, cycles);37 }38}39function deepCyclicCopyObject(object, options, cycles) {40 const newObject = options.keepPrototype ? Object.create(Object.getPrototypeOf(object)) : {};41 // $FlowFixMe: Object.getOwnPropertyDescriptors is polyfilled above.42 const descriptors = Object.getOwnPropertyDescriptors(object);43 cycles.set(object, newObject);44 Object.keys(descriptors).forEach(key => {45 if (options.blacklist && options.blacklist.has(key)) {46 delete descriptors[key];47 return;48 }49 const descriptor = descriptors[key];50 if (typeof descriptor.value !== 'undefined') {51 descriptor.value = deepCyclicCopy(descriptor.value, { blacklist: EMPTY, keepPrototype: options.keepPrototype }, cycles);52 }53 descriptor.configurable = true;54 });55 return Object.defineProperties(newObject, descriptors);56}57function deepCyclicCopyArray(array, options, cycles) {58 const newArray = options.keepPrototype ? // $FlowFixMe: getPrototypeOf an array is OK.59 new (Object.getPrototypeOf(array).constructor)(array.length) : [];60 const length = array.length;61 cycles.set(array, newArray);62 for (let i = 0; i < length; i++) {63 newArray[i] = deepCyclicCopy(array[i], { blacklist: EMPTY, keepPrototype: options.keepPrototype }, cycles);64 }65 return newArray;...
deepCyclicCopy.js
Source:deepCyclicCopy.js
...36 return value;37 } else if (cycles.has(value)) {38 return cycles.get(value);39 } else if (Array.isArray(value)) {40 return deepCyclicCopyArray(value, options, cycles);41 } else {42 return deepCyclicCopyObject(value, options, cycles);43 }44}45function deepCyclicCopyObject(object, options, cycles) {46 const newObject = options.keepPrototype47 ? Object.create(Object.getPrototypeOf(object))48 : {};49 const descriptors = Object.getOwnPropertyDescriptors(object);50 cycles.set(object, newObject);51 Object.keys(descriptors).forEach(key => {52 if (options.blacklist && options.blacklist.has(key)) {53 delete descriptors[key];54 return;55 }56 const descriptor = descriptors[key];57 if (typeof descriptor.value !== 'undefined') {58 descriptor.value = deepCyclicCopy(59 descriptor.value,60 {61 blacklist: EMPTY,62 keepPrototype: options.keepPrototype63 },64 cycles65 );66 }67 descriptor.configurable = true;68 });69 return Object.defineProperties(newObject, descriptors);70}71function deepCyclicCopyArray(array, options, cycles) {72 const newArray = options.keepPrototype73 ? new (Object.getPrototypeOf(array)).constructor(array.length)74 : [];75 const length = array.length;76 cycles.set(array, newArray);77 for (let i = 0; i < length; i++) {78 newArray[i] = deepCyclicCopy(79 array[i],80 {81 blacklist: EMPTY,82 keepPrototype: options.keepPrototype83 },84 cycles85 );...
LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.
|<p>it('check_object_of_Car', () => {</p><p>
expect(newCar()).toBeInstanceOf(Car);</p><p>
});</p>|
| :- |
Get 100 minutes of automation test minutes FREE!!