Skip to content

Commit

Permalink
100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzraho committed Jan 6, 2020
1 parent 2d85de7 commit 376a038
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/lib/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit 376a038

Please sign in to comment.