react-native-integrate
Version:
Automate integration of additional code into React Native projects
38 lines (37 loc) • 1.81 kB
JavaScript
;
/* eslint-disable @typescript-eslint/no-unsafe-call */
Object.defineProperty(exports, "__esModule", { value: true });
const { mockFs } = require('../../mocks/mockAll');
const mockStartSpinner = jest.spyOn(require('../../../prompter'), 'startSpinner');
const waitForFile_1 = require("../../../utils/waitForFile");
describe('waitForFile', () => {
it('should resolve false when file exists', async () => {
mockFs.writeFileSync('/test/file.json', 'test-content');
await expect((0, waitForFile_1.waitForFile)('/test/file.json')).resolves.toBe(false);
});
it('should resolve true when file not exists', async () => {
jest.useFakeTimers();
const promise = (0, waitForFile_1.waitForFile)('/test/file.json');
jest.advanceTimersToNextTimer();
await expect(promise).resolves.toBe(true);
});
it('should throw when has no permission', async () => {
mockFs.setReadPermission(false);
await expect((0, waitForFile_1.waitForFile)('/test/file.json')).rejects.toThrowError('permission denied');
});
it('should throw when has no permission', async () => {
mockFs.setReadPermission(false);
await expect((0, waitForFile_1.waitForFile)('/test/file.json')).rejects.toThrowError('permission denied');
});
it('should handle cancel', async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
jest.useFakeTimers();
mockStartSpinner.mockImplementationOnce(((_msg, onCancel) => {
setImmediate(() => onCancel());
}));
const promise = (0, waitForFile_1.waitForFile)('/test/file.json');
jest.advanceTimersToNextTimer();
await expect(promise).rejects.toThrowError('skip');
mockStartSpinner.mockReset();
});
});