How to use the ora.mockReturnValue function in ora

To help you get started, we’ve selected a few ora examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kefranabg / readme-md-generator / src / project-infos.spec.js View on Github external
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')
    })
github kefranabg / readme-md-generator / src / readme.spec.js View on Github external
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)

ora

Elegant terminal spinner

MIT
Latest version published 2 months ago

Package Health Score

88 / 100
Full package analysis