|
| 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 | +}); |
0 commit comments