From 376a038d62056cc5be51e7f8a2761a45067221ac Mon Sep 17 00:00:00 2001 From: Moritz Raho Date: Mon, 6 Jan 2020 17:05:30 +0100 Subject: [PATCH] 100% test coverage --- test/lib/utils.test.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/lib/utils.test.js b/test/lib/utils.test.js index 1515fa49..7b6ce865 100644 --- a/test/lib/utils.test.js +++ b/test/lib/utils.test.js @@ -8,3 +8,40 @@ describe('atLeastOne', () => { expect(utils.atLeastOne([])).toBe('please choose at least one option') }) }) + +describe('guessProjectName', () => { + test('returns cwd if package.json does not exist', () => { + const spy = jest.spyOn(process, 'cwd') + spy.mockReturnValue('FAKECWD') + expect(utils.guessProjectName({ + destinationPath: () => {}, + fs: { + exists: () => false + } + })).toEqual('FAKECWD') + spy.mockRestore() + }) + + test('returns cwd if package.json[name] is not defined', () => { + const spy = jest.spyOn(process, 'cwd') + spy.mockReturnValue('FAKECWD') + expect(utils.guessProjectName({ + destinationPath: () => {}, + fs: { + exists: () => true, + readJSON: () => ({}) + } + })).toEqual('FAKECWD') + spy.mockRestore() + }) + + test('returns package.json[name] if package.json exists and has a name attribut', () => { + expect(utils.guessProjectName({ + destinationPath: () => {}, + fs: { + exists: () => true, + readJSON: () => ({ name: 'FAKENAME' }) + } + })).toEqual('FAKENAME') + }) +})