Skip to content

Commit

Permalink
Current behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 27, 2022
1 parent 27eb77e commit bf75889
Show file tree
Hide file tree
Showing 5 changed files with 1,969 additions and 0 deletions.
80 changes: 80 additions & 0 deletions e2e/__tests__/toMatchInlineSnapshotWithJSX.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import * as path from 'path';
import * as fs from 'graceful-fs';
import {runYarnInstall} from '../Utils';
import {json as runWithJson} from '../runJest';

const DIR = path.resolve(__dirname, '..', 'to-match-inline-snapshot-with-jsx');

function cleanup() {
fs.copyFileSync(
path.join(DIR, 'MismatchingSnapshot.original.js'),
path.join(DIR, '__tests__/MismatchingSnapshot.test.js'),
);
}

beforeEach(() => {
runYarnInstall(DIR);
cleanup();
});

afterAll(() => {
cleanup();
});

it('successfully runs the tests inside `to-match-inline-snapshot-with-jsx/`', () => {
const updateSnapshotRun = runWithJson(DIR, ['--updateSnapshot']);
expect(updateSnapshotRun.json.testResults[0].message).toMatchInlineSnapshot(`
" ● Test suite failed to run
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):
3 |
4 | test('<div>x</div>', () => {
> 5 | expect(renderer.create(<div>x</div>).toJSON()).toMatchInlineSnapshot(\`
| ^
6 | <div>
7 | y
8 | </div>
Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.
at instantiate (../../node_modules/@babel/parser/src/parse-error/credentials.js:61:22)
"
`);

const normalRun = runWithJson(DIR, []);
expect(normalRun.json.testResults[0].message).toMatchInlineSnapshot(`
" ● <div>x</div>
expect(received).toMatchInlineSnapshot(snapshot)
Snapshot name: \`<div>x</div> 1\`
- Snapshot - 1
+ Received + 1
<div>
- y
+ x
</div>
3 |
4 | test('<div>x</div>', () => {
> 5 | expect(renderer.create(<div>x</div>).toJSON()).toMatchInlineSnapshot(\`
| ^
6 | <div>
7 | y
8 | </div>
at Object.toMatchInlineSnapshot (__tests__/MismatchingSnapshot.test.js:5:50)
"
`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import renderer from 'react-test-renderer';

test('<div>x</div>', () => {
expect(renderer.create(<div>x</div>).toJSON()).toMatchInlineSnapshot(`
<div>
y
</div>
`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import renderer from 'react-test-renderer';

test('<div>x</div>', () => {
expect(renderer.create(<div>x</div>).toJSON()).toMatchInlineSnapshot(`
<div>
y
</div>
`);
});
29 changes: 29 additions & 0 deletions e2e/to-match-inline-snapshot-with-jsx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"dependencies": {
"@babel/preset-env": "^7.14.4",
"@babel/preset-react": "^7.13.13",
"react": "^17.0.0",
"react-test-renderer": "^17.0.2"
},
"jest": {
"testEnvironment": "jsdom",
"transform": {
"^.+\\.(js|jsx)$": [
"babel-jest",
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-react"
]
}
]
}
}
}
Loading

0 comments on commit bf75889

Please sign in to comment.