Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call print for non-string children in ReactTestComponent plugin #3745

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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