diff --git a/src/utils/file-exists.test.ts b/src/utils/file-exists.test.ts new file mode 100644 index 00000000..ee8361b4 --- /dev/null +++ b/src/utils/file-exists.test.ts @@ -0,0 +1,27 @@ +import { promises as fs } from 'fs'; + +import { fileExists } from './file-exists'; + +describe('file-exists.ts', () => { + const accessMock = jest.spyOn(fs, 'access'); + + beforeEach(() => { + accessMock.mockReset(); + }); + + it('should check if a file exists - true', async () => { + accessMock.mockResolvedValueOnce(); + + const result = await fileExists('./hello.txt'); + + expect(result).toBe(true); + }); + + it('should check if a file exists - false', async () => { + accessMock.mockRejectedValueOnce(undefined); + + const result = await fileExists('./file-does-not-exist.txt'); + + expect(result).toBe(false); + }); +});