diff --git a/packages/enzyme-test-suite/test/Debug-spec.jsx b/packages/enzyme-test-suite/test/Debug-spec.jsx
index 7ecd6b2e4..fc9c586a3 100644
--- a/packages/enzyme-test-suite/test/Debug-spec.jsx
+++ b/packages/enzyme-test-suite/test/Debug-spec.jsx
@@ -626,6 +626,36 @@ describe('debug', () => {
span text
+`
+ ));
+ });
+
+ it('options.verbose causes arrays and objects to be verbosely printed', () => {
+ class Foo extends React.Component {
+ render() {
+ const nestedData = {
+ a: [1, 3, { true: true }],
+ b: false,
+ c: { d: 'f' },
+ };
+ nestedData.d = nestedData.a;
+ const arry = [1, 2, { f: nestedData.c }];
+ return (
+
Test Component
+ );
+ }
+ }
+
+ const wrapper = shallow();
+ expect(wrapper.debug({ verbose: true })).to.equal((
+ `
+ Test Component
+
`
+ ));
+
+ expect(wrapper.debug({ verbose: false })).to.equal((
+ `
+ Test Component
`
));
});
@@ -684,5 +714,39 @@ describe('debug', () => {
`
));
});
+
+ it('options.verbose causes arrays and objects to be verbosely printed', () => {
+ class Foo extends React.Component {
+ render() {
+ const nestedData = {
+ a: [1, 3, { true: true }],
+ b: false,
+ c: { d: 'f' },
+ };
+ nestedData.d = nestedData.a;
+ const arry = [1, 2, { f: nestedData.c }];
+ return (
+ Test Component
+ );
+ }
+ }
+
+ const wrapper = mount();
+ expect(wrapper.debug({ verbose: true })).to.equal((
+ `
+
+ Test Component
+
+`
+ ));
+
+ expect(wrapper.debug({ verbose: false })).to.equal((
+ `
+
+ Test Component
+
+`
+ ));
+ });
});
});
diff --git a/packages/enzyme/src/Debug.js b/packages/enzyme/src/Debug.js
index e82690c33..27ccb372a 100644
--- a/packages/enzyme/src/Debug.js
+++ b/packages/enzyme/src/Debug.js
@@ -29,7 +29,7 @@ export function indent(depth, string) {
return string.split('\n').map(x => `${spaces(depth)}${x}`).join('\n');
}
-function propString(prop) {
+function propString(prop, options) {
if (isString(prop)) {
return inspect(String(prop), { quoteStyle: 'double' });
}
@@ -43,15 +43,19 @@ function propString(prop) {
return `{${inspect(prop)}}`;
}
if (typeof prop === 'object') {
+ if (options.verbose) {
+ return `{${inspect(prop)}}`;
+ }
+
return '{{...}}';
}
return `{[${typeof prop}]}`;
}
-function propsString(node) {
+function propsString(node, options) {
const props = propsOfNode(node);
const keys = without(Object.keys(props), 'children');
- return keys.map(key => `${key}=${propString(props[key])}`).join(' ');
+ return keys.map(key => `${key}=${propString(props[key], options)}`).join(' ');
}
function indentChildren(childrenStrs, indentLength) {
@@ -67,7 +71,7 @@ export function debugNode(node, indentLength = 2, options = {}) {
const childrenStrs = compact(childrenOfNode(node).map(n => debugNode(n, indentLength, options)));
const type = typeName(node);
- const props = options.ignoreProps ? '' : propsString(node);
+ const props = options.ignoreProps ? '' : propsString(node, options);
const beforeProps = props ? ' ' : '';
const afterProps = childrenStrs.length
? '>'
diff --git a/packages/enzyme/src/ReactWrapper.js b/packages/enzyme/src/ReactWrapper.js
index 326b9a547..96f5f117c 100644
--- a/packages/enzyme/src/ReactWrapper.js
+++ b/packages/enzyme/src/ReactWrapper.js
@@ -989,8 +989,9 @@ class ReactWrapper {
/**
* Returns an HTML-like string of the shallow render for debugging purposes.
*
- * @param {Object} options - (Optional) Property bag of additional options.
- * options.ignoreProps - if true, props are omitted from the string.
+ * @param {Object} [options] - Property bag of additional options.
+ * @param {boolean} [options.ignoreProps] - if true, props are omitted from the string.
+ * @param {boolean} [options.verbose] - if true, arrays and objects to be verbosely printed.
* @returns {String}
*/
debug(options = {}) {
diff --git a/packages/enzyme/src/ShallowWrapper.js b/packages/enzyme/src/ShallowWrapper.js
index 2144bc630..5a76c63c7 100644
--- a/packages/enzyme/src/ShallowWrapper.js
+++ b/packages/enzyme/src/ShallowWrapper.js
@@ -1132,8 +1132,9 @@ class ShallowWrapper {
/**
* Returns an HTML-like string of the shallow render for debugging purposes.
*
- * @param {Object} options - (Optional) Property bag of additional options.
- * options.ignoreProps - if true, props are omitted from the string.
+ * @param {Object} [options] - Property bag of additional options.
+ * @param {boolean} [options.ignoreProps] - if true, props are omitted from the string.
+ * @param {boolean} [options.verbose] - if true, arrays and objects to be verbosely printed.
* @returns {String}
*/
debug(options = {}) {