mirror of
https://github.com/status-im/react-native.git
synced 2025-01-20 22:39:20 +00:00
b3fc64285e
Reviewed By: rafeca Differential Revision: D5931412 fbshipit-source-id: 2b51617b57963c424446b04e9381e6500323af56
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* @emails oncall+javascript_foundation
|
|
* @flow
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
/* eslint-disable no-unclear-flowtypes */
|
|
|
|
declare var jest: any;
|
|
declare var describe: any;
|
|
declare var it: any;
|
|
|
|
jest.mock('fs');
|
|
|
|
const fs = require('fs');
|
|
|
|
describe('fs mock', () => {
|
|
describe('writeFileSync()', () => {
|
|
it('stores content correctly', () => {
|
|
fs.writeFileSync('/test', 'foobar', 'utf8');
|
|
const content = fs.readFileSync('/test', 'utf8');
|
|
expect(content).toEqual('foobar');
|
|
});
|
|
|
|
it('fails on missing path', () => {
|
|
expect(() =>
|
|
fs.writeFileSync('/dir/test', 'foobar', 'utf8'),
|
|
).toThrowError('ENOENT: no such file or directory');
|
|
});
|
|
});
|
|
|
|
describe('mkdirSync()', () => {
|
|
it('creates folders that we can write files in', () => {
|
|
fs.mkdirSync('/dir', 0o777);
|
|
fs.writeFileSync('/dir/test', 'foobar', 'utf8');
|
|
const content = fs.readFileSync('/dir/test', 'utf8');
|
|
expect(content).toEqual('foobar');
|
|
});
|
|
});
|
|
});
|