Repository URL to install this package:
|
Version:
4.2.0 ▾
|
const fs = require('fs');
const { writeJsonFile, readJsonFile, getResourceConfiguration } = require('./utils');
jest.mock('fs');
describe('Utility functions', () => {
test('writeJsonFile', async () => {
fs.writeFile.mockImplementation((_, __, cb) => {
cb(null);
});
await writeJsonFile('i18n/en.json', { key: 'value' });
expect(fs.writeFile).toHaveBeenCalledWith('i18n/en.json', '{"key":"value"}', expect.any(Function));
});
test('readJsonFile', async () => {
fs.readFile.mockImplementation((_, cb) => {
cb(null, '{"key":"value"}');
});
const config = await readJsonFile('i18n/en.json');
expect(config).toEqual({ key: 'value' });
});
test('getResourceConfiguration', async () => {
fs.readFile.mockImplementation((_, cb) => {
cb(null, '{"key":"value"}');
});
const config = await getResourceConfiguration('.oneskyrc');
expect(config).toEqual({ key: 'value' });
});
});