forked from jestjs/jest
/
snapshotSerializers.test.ts
46 lines (40 loc) · 1.33 KB
/
snapshotSerializers.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* 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 path from 'path';
import {cleanup} from '../Utils';
import {json as runWithJson} from '../runJest';
const testDir = path.resolve(__dirname, '../snapshot-serializers');
const snapshotsDir = path.resolve(testDir, '__tests__/__snapshots__');
const snapshotPath = path.resolve(snapshotsDir, 'snapshot.test.js.snap');
const runAndAssert = () => {
const result = runWithJson('snapshot-serializers', [
'-w=1',
'--ci=false',
'--no-cache',
]);
const json = result.json;
expect(json.numTotalTests).toBe(9);
expect(json.numPassedTests).toBe(9);
expect(json.numFailedTests).toBe(0);
expect(json.numPendingTests).toBe(0);
expect(result.status).toBe(0);
};
describe('Snapshot serializers', () => {
beforeEach(() => cleanup(snapshotsDir));
afterEach(() => cleanup(snapshotsDir));
it('renders snapshot', () => {
runAndAssert();
// $FlowFixMe dynamic require
const snapshot = require(snapshotPath);
expect(snapshot).toMatchSnapshot();
});
it('compares snapshots correctly', () => {
// run twice, second run compares result with snapshot from first run
runAndAssert();
runAndAssert();
});
});