-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
snapshotMockFs.test.ts
37 lines (30 loc) · 1.15 KB
/
snapshotMockFs.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
/**
* 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 rimraf = require('rimraf');
import {wrap} from 'jest-snapshot-serializer-raw';
import {extractSummary} from '../Utils';
import {json as runJestJson} from '../runJest';
const DIR = path.resolve(__dirname, '../snapshot-mock-fs');
const snapshotDir = path.resolve(DIR, '__tests__/__snapshots__');
const snapshotFile = path.resolve(snapshotDir, 'snapshot.test.js.snap');
beforeEach(() => rimraf.sync(snapshotDir));
afterAll(() => rimraf.sync(snapshotDir));
test('store snapshot even if fs is mocked', () => {
const {json, status, stderr} = runJestJson(DIR, ['--ci=false']);
expect(status).toBe(0);
expect(json.numTotalTests).toBe(1);
expect(json.numPassedTests).toBe(1);
expect(stderr).toMatch('1 snapshot written from 1 test suite.');
expect(wrap(extractSummary(stderr).summary)).toMatchSnapshot();
const content = require(snapshotFile);
expect(content['snapshot 1']).toBe(`
Object {
"foo": "bar",
}
`);
});