Skip to content

Commit bf75889

Browse files
committed
Current behavior
1 parent 27eb77e commit bf75889

File tree

5 files changed

+1969
-0
lines changed

5 files changed

+1969
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import * as path from 'path';
9+
import * as fs from 'graceful-fs';
10+
import {runYarnInstall} from '../Utils';
11+
import {json as runWithJson} from '../runJest';
12+
13+
const DIR = path.resolve(__dirname, '..', 'to-match-inline-snapshot-with-jsx');
14+
15+
function cleanup() {
16+
fs.copyFileSync(
17+
path.join(DIR, 'MismatchingSnapshot.original.js'),
18+
path.join(DIR, '__tests__/MismatchingSnapshot.test.js'),
19+
);
20+
}
21+
22+
beforeEach(() => {
23+
runYarnInstall(DIR);
24+
cleanup();
25+
});
26+
27+
afterAll(() => {
28+
cleanup();
29+
});
30+
31+
it('successfully runs the tests inside `to-match-inline-snapshot-with-jsx/`', () => {
32+
const updateSnapshotRun = runWithJson(DIR, ['--updateSnapshot']);
33+
expect(updateSnapshotRun.json.testResults[0].message).toMatchInlineSnapshot(`
34+
" ● Test suite failed to run
35+
36+
SyntaxError: /home/eps1lon/Development/forks/jest/e2e/to-match-inline-snapshot-with-jsx/__tests__/MismatchingSnapshot.test.js: Support for the experimental syntax 'jsx' isn't currently enabled (5:26):
37+
38+
3 |
39+
4 | test('<div>x</div>', () => {
40+
> 5 | expect(renderer.create(<div>x</div>).toJSON()).toMatchInlineSnapshot(\`
41+
| ^
42+
6 | <div>
43+
7 | y
44+
8 | </div>
45+
46+
Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
47+
If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.
48+
49+
at instantiate (../../node_modules/@babel/parser/src/parse-error/credentials.js:61:22)
50+
"
51+
`);
52+
53+
const normalRun = runWithJson(DIR, []);
54+
expect(normalRun.json.testResults[0].message).toMatchInlineSnapshot(`
55+
" ● <div>x</div>
56+
57+
expect(received).toMatchInlineSnapshot(snapshot)
58+
59+
Snapshot name: \`<div>x</div> 1\`
60+
61+
- Snapshot - 1
62+
+ Received + 1
63+
64+
<div>
65+
- y
66+
+ x
67+
</div>
68+
69+
3 |
70+
4 | test('<div>x</div>', () => {
71+
> 5 | expect(renderer.create(<div>x</div>).toJSON()).toMatchInlineSnapshot(\`
72+
| ^
73+
6 | <div>
74+
7 | y
75+
8 | </div>
76+
77+
at Object.toMatchInlineSnapshot (__tests__/MismatchingSnapshot.test.js:5:50)
78+
"
79+
`);
80+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import renderer from 'react-test-renderer';
3+
4+
test('<div>x</div>', () => {
5+
expect(renderer.create(<div>x</div>).toJSON()).toMatchInlineSnapshot(`
6+
<div>
7+
y
8+
</div>
9+
`);
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import renderer from 'react-test-renderer';
3+
4+
test('<div>x</div>', () => {
5+
expect(renderer.create(<div>x</div>).toJSON()).toMatchInlineSnapshot(`
6+
<div>
7+
y
8+
</div>
9+
`);
10+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"dependencies": {
3+
"@babel/preset-env": "^7.14.4",
4+
"@babel/preset-react": "^7.13.13",
5+
"react": "^17.0.0",
6+
"react-test-renderer": "^17.0.2"
7+
},
8+
"jest": {
9+
"testEnvironment": "jsdom",
10+
"transform": {
11+
"^.+\\.(js|jsx)$": [
12+
"babel-jest",
13+
{
14+
"presets": [
15+
[
16+
"@babel/preset-env",
17+
{
18+
"targets": {
19+
"node": "current"
20+
}
21+
}
22+
],
23+
"@babel/preset-react"
24+
]
25+
}
26+
]
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)