Socket
Socket
Sign inDemoInstall

jest-util

Package Overview
Dependencies
Maintainers
5
Versions
261
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-util - npm Package Compare versions

Comparing version 12.0.0 to 12.0.1

50

lib/__tests__/JasmineFormatter-test.js

@@ -14,2 +14,3 @@ /**

const chalk = require('chalk');
const jasmine = require('jest-jasmine1/vendor/jasmine-1.3.0').jasmine;

@@ -28,2 +29,6 @@ const jasmine2Require = require('jest-jasmine2/vendor/jasmine-2.4.1.js');

describe('pretty printer', () => {
beforeEach(() => {
formatter = new JasmineFormatter(jasmine2);
});
it('should handle JSDOM nodes with Jasmine 1.x', () => {

@@ -36,7 +41,48 @@ formatter = new JasmineFormatter(jasmine);

it('should handle JSDOM nodes with Jasmine 2.x', () => {
formatter = new JasmineFormatter(jasmine2);
expect(() => formatter.prettyPrint(jsdom(fixture).body)).not.toThrow();
});
it('should pretty print Maps', () => {
const map = new Map([['foo', {
bar: 'baz',
}]]);
const printed = formatter.prettyPrint(map);
const expected = 'Map {\n' +
'| foo: {\n' +
'| | bar: \'baz\'\n' +
'| }\n' +
'}';
expect(printed).toBe(expected.replace(/\|/g, chalk.gray('|')));
});
it('should pretty print Sets', () => {
const set = new Set(['a', 'b', 'c']);
const printed = formatter.prettyPrint(set);
expect(printed).toBe(`Set [\n'a', 'b', 'c'\n]`);
});
it('should pretty print mix of Sets, Maps and plain objects', () => {
const map = new Map([['foo', {
bar: 'baz',
set: new Set(['a', 'b', {
foo: 'bar',
baz: 'foo',
}]),
}]]);
const printed = formatter.prettyPrint(map);
const expected = 'Map {\n' +
'| foo: {\n' +
'| | bar: \'baz\',\n' +
'| | set: Set [\n' +
'| | \'a\', \'b\', {\n' +
'| | | | baz: \'foo\',\n' +
'| | | | foo: \'bar\'\n' +
'| | | }\n' +
'| | ]\n' +
'| }\n' +
'}';
expect(printed).toBe(expected.replace(/\|/g, chalk.gray('|')));
});
});
});

49

lib/JasmineFormatter.js

@@ -104,3 +104,3 @@ /**

prettyPrint(obj, indent, cycleWeakMap) {
prettyPrint(object, indent, cycleWeakMap) {
if (!indent) {

@@ -110,6 +110,7 @@ indent = '';

if (typeof obj === 'object' && obj !== null) {
if (this._jasmine.isDomNode(obj)) {
if (typeof object === 'object' && object !== null) {
if (this._jasmine.isDomNode(object)) {
let attrStr = '';
Array.prototype.forEach.call(obj.attributes, attr => {
Array.prototype.forEach.call(object.attributes, attr => {
const attrName = attr.name.trim();

@@ -120,3 +121,3 @@ const attrValue = attr.value.trim();

return (
'HTMLNode(<' + obj.tagName + attrStr + '>{...}</' + obj.tagName + '>)'
`HTMLNode(<${object.tagName + attrStr}>{...}</${object.tagName}>)`
);

@@ -129,8 +130,36 @@ }

if (cycleWeakMap.get(obj) === true) {
if (cycleWeakMap.get(object) === true) {
return '<circular reference>';
}
cycleWeakMap.set(obj, true);
cycleWeakMap.set(object, true);
const orderedKeys = Object.keys(obj).sort();
const type = Object.prototype.toString.call(object);
const output = [];
if (type === '[object Map]') {
indent = chalk.gray('|') + ' ' + indent;
for (const value of object) {
output.push(
indent + value[0] + ': ' + this.prettyPrint(
value[1],
indent,
cycleWeakMap
)
);
}
return `Map {\n${output.join(',')}\n}`;
}
if (type === '[object Set]') {
for (const value of object) {
output.push(
this.prettyPrint(
value,
chalk.gray('|') + ' ' + indent,
cycleWeakMap
)
);
}
return `Set [\n${indent}${output.join(', ')}\n${indent}]`;
}
const orderedKeys = Object.keys(object).sort();
let value;

@@ -140,3 +169,3 @@ const keysOutput = [];

for (let i = 0; i < orderedKeys.length; i++) {
value = obj[orderedKeys[i]];
value = object[orderedKeys[i]];
keysOutput.push(

@@ -149,3 +178,3 @@ indent + keyIndent + orderedKeys[i] + ': ' +

} else {
return this._jasmine.pp(obj);
return this._jasmine.pp(object);
}

@@ -152,0 +181,0 @@ }

{
"name": "jest-util",
"version": "12.0.0",
"version": "12.0.1",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc