Skip to content

Commit

Permalink
Put JSX closing brackets in new line in snapshots (#2832)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbujok authored and cpojer committed Feb 8, 2017
1 parent 9bdb555 commit 204e46c
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 47 deletions.
30 changes: 20 additions & 10 deletions examples/react-native/__tests__/__snapshots__/Intro-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ exports[`test renders correctly 1`] = `
"flex": 1,
"justifyContent": "center",
}
}>
}
>
<Text
accessible={true}
allowFontScaling={true}
Expand All @@ -18,7 +19,8 @@ exports[`test renders correctly 1`] = `
"margin": 10,
"textAlign": "center",
}
}>
}
>
Welcome to React Native!
</Text>
<Text
Expand All @@ -31,7 +33,8 @@ exports[`test renders correctly 1`] = `
"marginBottom": 5,
"textAlign": "center",
}
}>
}
>
This is a React Native snapshot test.
</Text>
</View>
Expand All @@ -42,7 +45,8 @@ exports[`test renders the ActivityIndicator component 1`] = `
animating={true}
color="#999999"
hidesWhenStopped={true}
size="small" />
size="small"
/>
`;

exports[`test renders the Image component 1`] = `
Expand All @@ -52,7 +56,8 @@ exports[`test renders the Image component 1`] = `
"height": 240,
"width": 320,
}
} />
}
/>
`;

exports[`test renders the ListView component 1`] = `
Expand All @@ -76,23 +81,27 @@ exports[`test renders the ListView component 1`] = `
renderRow={[Function]}
scrollEventThrottle={50}
scrollRenderAheadDistance={1000}
stickyHeaderIndices={Array []}>
stickyHeaderIndices={Array []}
>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail">
ellipsizeMode="tail"
>
apple
</Text>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail">
ellipsizeMode="tail"
>
banana
</Text>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail">
ellipsizeMode="tail"
>
kiwi
</Text>
</ScrollView>
Expand All @@ -101,5 +110,6 @@ exports[`test renders the ListView component 1`] = `
exports[`test renders the TextInput component 1`] = `
<TextInput
autoCorrect={false}
value="apple banana kiwi" />
value="apple banana kiwi"
/>
`;
18 changes: 12 additions & 6 deletions examples/snapshot/__tests__/__snapshots__/Link.react-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ exports[`test changes the class when hovered 1`] = `
className="normal"
href="http://www.facebook.com"
onMouseEnter={[Function]}
onMouseLeave={[Function]}>
onMouseLeave={[Function]}
>
Facebook
</a>
`;
Expand All @@ -13,7 +14,8 @@ exports[`test changes the class when hovered 2`] = `
className="hovered"
href="http://www.facebook.com"
onMouseEnter={[Function]}
onMouseLeave={[Function]}>
onMouseLeave={[Function]}
>
Facebook
</a>
`;
Expand All @@ -23,7 +25,8 @@ exports[`test changes the class when hovered 3`] = `
className="normal"
href="http://www.facebook.com"
onMouseEnter={[Function]}
onMouseLeave={[Function]}>
onMouseLeave={[Function]}
>
Facebook
</a>
`;
Expand All @@ -33,7 +36,8 @@ exports[`test properly escapes quotes 1`] = `
className="normal"
href="#"
onMouseEnter={[Function]}
onMouseLeave={[Function]}>
onMouseLeave={[Function]}
>
"Facebook" \\'is \\ 'awesome'
</a>
`;
Expand All @@ -43,7 +47,8 @@ exports[`test renders as an anchor when no page is set 1`] = `
className="normal"
href="#"
onMouseEnter={[Function]}
onMouseLeave={[Function]}>
onMouseLeave={[Function]}
>
Facebook
</a>
`;
Expand All @@ -53,7 +58,8 @@ exports[`test renders correctly 1`] = `
className="normal"
href="http://www.facebook.com"
onMouseEnter={[Function]}
onMouseLeave={[Function]}>
onMouseLeave={[Function]}
>
Facebook
</a>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ exports[`Snapshot serializers renders snapshot 1`] = `
Object {
"snapshot serializers works with default serializers 1": "
<div
id=\\"foo\\" />
id=\\"foo\\"
/>
",
"snapshot serializers works with first plugin 1": "foo: 1",
"snapshot serializers works with nested serializable objects 1": "foo: bar: 2",
Expand All @@ -13,7 +14,8 @@ Object {
\\"a\\": 6,
}
}
bProp={foo: 8} />
bProp={foo: 8}
/>
",
"snapshot serializers works with prepended plugins from expect method called once 1": "
<div
Expand All @@ -22,7 +24,8 @@ Object {
\\"a\\": 6,
}
}
bProp={Foo: 8} />
bProp={Foo: 8}
/>
",
"snapshot serializers works with prepended plugins from expect method called twice 1": "
<div
Expand All @@ -31,7 +34,8 @@ Object {
\\"a\\": 6,
}
}
bProp={FOO: 8} />
bProp={FOO: 8}
/>
",
"snapshot serializers works with second plugin 1": "bar: 2",
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
exports[`test generates a snapshot with correctly transformed dependencies 1`] = `
<div
className="App-root">
className="App-root"
>
<div
className="App-header">
className="App-header"
>
<img
alt="logo"
className="App-logo"
src="logo.svg" />
src="logo.svg"
/>
<h2
className={undefined}>
className={undefined}
>
Welcome to React
</h2>
</div>
<p
className="App-intro">
className="App-intro"
>
To get started, edit
<code>
src/App.js
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-diff/src/__tests__/diff-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ test('React elements', () => {
},
type: 'div',
});
expect(stripAnsi(result)).toMatch(/<div[\s\S]+className="fun">/);
expect(stripAnsi(result)).toMatch(/<div\n/);
expect(stripAnsi(result)).toMatch(/[\s\S]+className="fun"\n/);
expect(stripAnsi(result)).toMatch(/>/);
expect(stripAnsi(result)).toMatch(/\-\s+Hello/);
expect(stripAnsi(result)).toMatch(/\+\s+Goodbye/);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ exports[`prettyFormat() ReactTestComponent and ReactElement plugins ReactElement
rat
</span>
</div>
} />"
}
/>"
`;
exports[`prettyFormat() ReactTestComponent and ReactElement plugins ReactTestComponent plugin highlights syntax 1`] = `
Expand All @@ -19,5 +20,6 @@ exports[`prettyFormat() ReactTestComponent and ReactElement plugins ReactTestCom
rat
</span>
</div>
} />"
}
/>"
`;
30 changes: 15 additions & 15 deletions packages/pretty-format/src/__tests__/pretty-format-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,28 +416,28 @@ describe('prettyFormat()', () => {
it('supports props with strings', () => {
assertPrintedJSX(
React.createElement('Mouse', {style: 'color:red'}),
'<Mouse\n style="color:red" />'
'<Mouse\n style="color:red"\n/>'
);
});

it('supports props with numbers', () => {
assertPrintedJSX(
React.createElement('Mouse', {size: 5}),
'<Mouse\n size={5} />'
'<Mouse\n size={5}\n/>'
);
});

it('supports a single element with a function prop', () => {
assertPrintedJSX(
React.createElement('Mouse', {onclick: function onclick() {}}),
'<Mouse\n onclick={[Function onclick]} />'
'<Mouse\n onclick={[Function onclick]}\n/>'
);
});

it('supports a single element with a object prop', () => {
assertPrintedJSX(
React.createElement('Mouse', {customProp: {one: '1', two: 2}}),
'<Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n } />'
'<Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n/>'
);
});

Expand All @@ -446,7 +446,7 @@ describe('prettyFormat()', () => {
React.createElement('Mouse', {customProp: {one: '1', two: 2}},
React.createElement('Mouse')
),
'<Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n }>\n <Mouse />\n</Mouse>'
'<Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n>\n <Mouse />\n</Mouse>'
);
});

Expand All @@ -456,7 +456,7 @@ describe('prettyFormat()', () => {
'HELLO',
React.createElement('Mouse'), 'CIAO'
),
'<Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n onclick={[Function onclick]}>\n HELLO\n <Mouse />\n CIAO\n</Mouse>'
'<Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n onclick={[Function onclick]}\n>\n HELLO\n <Mouse />\n CIAO\n</Mouse>'
);
});

Expand All @@ -482,7 +482,7 @@ describe('prettyFormat()', () => {
),
'CIAO'
),
'<Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n onclick={[Function onclick]}>\n HELLO\n <Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n onclick={[Function onclick]}>\n HELLO\n <Mouse />\n CIAO\n </Mouse>\n CIAO\n</Mouse>'
'<Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n onclick={[Function onclick]}\n>\n HELLO\n <Mouse\n customProp={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n onclick={[Function onclick]}\n >\n HELLO\n <Mouse />\n CIAO\n </Mouse>\n CIAO\n</Mouse>'
);
});

Expand Down Expand Up @@ -510,7 +510,7 @@ describe('prettyFormat()', () => {
'NESTED'
)
),
'<Mouse\n abc={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n zeus="kentaromiura watched me fix this">\n <Mouse\n acbd={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n xyz={123}>\n NESTED\n </Mouse>\n</Mouse>'
'<Mouse\n abc={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n zeus="kentaromiura watched me fix this"\n>\n <Mouse\n acbd={\n Object {\n "one": "1",\n "two": 2,\n }\n }\n xyz={123}\n >\n NESTED\n </Mouse>\n</Mouse>'
);
/* eslint-enable sort-keys */
});
Expand All @@ -520,7 +520,7 @@ describe('prettyFormat()', () => {
React.createElement('Mouse', {
prop: React.createElement('div'),
}),
'<Mouse\n prop={<div />} />'
'<Mouse\n prop={<div />}\n/>'
);
});

Expand All @@ -529,7 +529,7 @@ describe('prettyFormat()', () => {
React.createElement('Mouse', {
prop: React.createElement('div', {foo: 'bar'}),
}),
'<Mouse\n prop={\n <div\n foo="bar" />\n } />'
'<Mouse\n prop={\n <div\n foo="bar"\n />\n }\n/>'
);
});

Expand All @@ -541,7 +541,7 @@ describe('prettyFormat()', () => {
React.createElement('Mouse', {
prop: React.createElement(Cat, {foo: 'bar'}),
}),
'<Mouse\n prop={\n <Cat\n foo="bar" />\n } />'
'<Mouse\n prop={\n <Cat\n foo="bar"\n />\n }\n/>'
);
});

Expand All @@ -553,7 +553,7 @@ describe('prettyFormat()', () => {
React.createElement('Mouse', {
prop: React.createElement(Cat, {}, React.createElement('div')),
}),
'<Mouse\n prop={\n <Cat>\n <div />\n </Cat>\n } />'
'<Mouse\n prop={\n <Cat>\n <div />\n </Cat>\n }\n/>'
);
});

Expand All @@ -562,7 +562,7 @@ describe('prettyFormat()', () => {
React.createElement('Mouse', {
prop: React.createElement('div', null, 'mouse'),
}),
'<Mouse\n prop={\n <div>\n mouse\n </div>\n } />'
'<Mouse\n prop={\n <div>\n mouse\n </div>\n }\n/>'
);
});

Expand All @@ -571,7 +571,7 @@ describe('prettyFormat()', () => {
React.createElement('Mouse', {
prop: React.createElement('div', null, 'mouse', React.createElement('span', null, 'rat')),
}),
'<Mouse\n prop={\n <div>\n mouse\n <span>\n rat\n </span>\n </div>\n } />'
'<Mouse\n prop={\n <div>\n mouse\n <span>\n rat\n </span>\n </div>\n }\n/>'
);
});

Expand All @@ -586,7 +586,7 @@ describe('prettyFormat()', () => {
],
),
}),
'<Mouse\n prop={\n <div>\n mouse\n <span>\n rat\n </span>\n <span>\n cat\n </span>\n </div>\n } />'
'<Mouse\n prop={\n <div>\n mouse\n <span>\n rat\n </span>\n <span>\n cat\n </span>\n </div>\n }\n/>'
);
});

Expand Down
1 change: 1 addition & 0 deletions packages/pretty-format/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ function printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDep

const opts = {
edgeSpacing,
min,
spacing,
};
return plugin.print(val, boundPrint, boundIndent, opts, colors);
Expand Down
Loading

0 comments on commit 204e46c

Please sign in to comment.