1import spawnAsync from '@expo/spawn-async'; 2import editors from 'env-editor'; 3 4import { asMock } from '../../__tests__/asMock'; 5import { guessEditor, openInEditorAsync } from '../editor'; 6 7jest.mock('../../log'); 8 9describe(guessEditor, () => { 10 it(`defaults to vscode if the default editor cannot be guessed`, () => { 11 asMock(editors.defaultEditor).mockImplementationOnce(() => { 12 throw new Error('Could not guess default editor'); 13 }); 14 guessEditor(); 15 expect(editors.getEditor).toBeCalledWith('vscode'); 16 }); 17}); 18 19describe(openInEditorAsync, () => { 20 it(`fails to open in a given editor that does not exist`, async () => { 21 asMock(editors.defaultEditor).mockReturnValueOnce({ 22 name: 'my-editor', 23 binary: 'my-editor-binary', 24 id: 'my-editor-id', 25 } as any); 26 asMock(spawnAsync).mockImplementationOnce(() => { 27 throw new Error('failed'); 28 }); 29 30 await expect(openInEditorAsync('/foo/bar')).resolves.toBe(false); 31 32 expect(spawnAsync).toBeCalledWith('my-editor-binary', ['/foo/bar']); 33 expect(spawnAsync).toBeCalledTimes(1); 34 }); 35}); 36