Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
jest.mock('child_process', () => ({
execSync: jest.fn()
}))
jest.mock('./utils', () => ({
getPackageJson: jest.fn(),
getProjectName: jest.fn(() => 'readme-md-generator'),
getAuthorWebsiteFromGithubAPI: jest.fn(
() => 'https://www.franck-abgrall.me/'
),
getPackageManagerFromLockFile: jest.fn(() => 'yarn')
}))
const succeed = jest.fn()
const fail = jest.fn()
ora.mockReturnValue({
start: () => ({
succeed,
fail
})
})
describe('projectInfos', () => {
describe('getProjectInfos', () => {
it('should call ora with correct parameters', async () => {
await getProjectInfos()
expect(ora).toHaveBeenCalledTimes(1)
expect(ora).toHaveBeenCalledWith('Gathering project infos')
expect(succeed).toHaveBeenCalledTimes(1)
expect(succeed).toHaveBeenCalledWith('Project infos gathered')
})
describe('readme', () => {
const succeed = jest.fn()
const fail = jest.fn()
ora.mockReturnValue({
start: () => ({
succeed,
fail
})
})
afterEach(() => {
jest.clearAllMocks()
})
describe('writeReadme', () => {
it('should call ora with correct parameters in success case', async () => {
const readmeContent = 'content'
fs.writeFile = jest.fn((_, __, cb) => cb(null, 'done'))
await writeReadme(readmeContent)