|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 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 {skipSuiteOnJasmine} from '@jest/test-utils'; |
| 11 | +import runJest from '../runJest'; |
| 12 | + |
| 13 | +skipSuiteOnJasmine(); |
| 14 | + |
| 15 | +describe('test.failing', () => { |
| 16 | + describe('should pass when', () => { |
| 17 | + test.failing('snapshot matchers fails', () => { |
| 18 | + expect('0').toMatchSnapshot(); |
| 19 | + }); |
| 20 | + |
| 21 | + test.failing('snapshot doesnt exist', () => { |
| 22 | + expect('0').toMatchSnapshot(); |
| 23 | + }); |
| 24 | + |
| 25 | + test.failing('inline snapshot matchers fails', () => { |
| 26 | + expect('0').toMatchInlineSnapshot('0'); |
| 27 | + }); |
| 28 | + |
| 29 | + test.failing('at least one snapshot fails', () => { |
| 30 | + expect('1').toMatchSnapshot(); |
| 31 | + expect('0').toMatchSnapshot(); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('should fail when', () => { |
| 36 | + test.each([ |
| 37 | + ['snapshot', 'snapshot'], |
| 38 | + ['inline snapshot', 'inlineSnapshot'], |
| 39 | + ])('%s matchers pass', (_, fileName) => { |
| 40 | + const dir = path.resolve(__dirname, '../test-failing-snapshot-all-pass'); |
| 41 | + const result = runJest(dir, [`./__tests__/${fileName}.test.js`]); |
| 42 | + expect(result.exitCode).toBe(1); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + it('doesnt update or remove snapshots', () => { |
| 47 | + const dir = path.resolve(__dirname, '../test-failing-snapshot'); |
| 48 | + const result = runJest(dir, ['-u']); |
| 49 | + expect(result.exitCode).toBe(0); |
| 50 | + expect(result.stdout).not.toMatch(/snapshots? (written|removed|obsolete)/); |
| 51 | + |
| 52 | + const snapshot = fs |
| 53 | + .readFileSync( |
| 54 | + path.resolve(dir, './__tests__/__snapshots__/snapshot.test.js.snap'), |
| 55 | + ) |
| 56 | + .toString(); |
| 57 | + expect(snapshot).toMatchSnapshot(); |
| 58 | + |
| 59 | + const inlineSnapshot = fs |
| 60 | + .readFileSync(path.resolve(dir, './__tests__/inlineSnapshot.test.js')) |
| 61 | + .toString(); |
| 62 | + expect(inlineSnapshot).toMatchSnapshot(); |
| 63 | + }); |
| 64 | +}); |
0 commit comments