Skip to content

Commit

Permalink
Call print for non-string children in ReactTestComponent plugin (jest…
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrottimark authored and cpojer committed Jun 6, 2017
1 parent 8b4c23d commit 8ef51e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
ReactTestComponent,
} = require('pretty-format').plugins;

let PLUGINS = [HTMLElement, ReactElement, ReactTestComponent].concat(Immutable);
let PLUGINS = [ReactTestComponent, ReactElement, HTMLElement].concat(Immutable);

// Prepend to list so the last added is the first tested.
exports.addSerializer = (plugin: Plugin) => {
Expand Down
32 changes: 15 additions & 17 deletions packages/pretty-format/src/plugins/ReactTestComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ function printChildren(
opts,
) {
return children
.map(child => printInstance(child, print, indent, colors, opts))
.map(node => {
if (typeof node === 'string') {
return colors.content.open + escapeHTML(node) + colors.content.close;
} else {
return print(node);
}
})
.join(opts.edgeSpacing);
}

Expand Down Expand Up @@ -63,13 +69,13 @@ function printProps(props: Object, print, indent, colors, opts) {
.join('');
}

function printInstance(instance: ReactTestChild, print, indent, colors, opts) {
if (typeof instance == 'number') {
return print(instance);
} else if (typeof instance === 'string') {
return colors.content.open + escapeHTML(instance) + colors.content.close;
}

const print = (
instance: ReactTestObject,
print: Print,
indent: Indent,
opts: Options,
colors: Colors,
) => {
let closeInNewLine = false;
let result = colors.tag.open + '<' + instance.type + colors.tag.close;

Expand Down Expand Up @@ -105,15 +111,7 @@ function printInstance(instance: ReactTestChild, print, indent, colors, opts) {
}

return result;
}

const print = (
val: ReactTestObject,
print: Print,
indent: Indent,
opts: Options,
colors: Colors,
) => printInstance(val, print, indent, colors, opts);
};

const test = (object: Object) =>
object && object.$$typeof === reactTestInstance;
Expand Down

0 comments on commit 8ef51e9

Please sign in to comment.