How to use the readline-sync.mock function in readline-sync

To help you get started, we’ve selected a few readline-sync 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 sezna / nps / src / bin-utils / __tests__ / parser.js View on Github external
test('init without an existing package.json will fail', () => {
  mockFindUp.mock.syncFail = true
  mockFindUp.mock.syncReturn = undefined

  const result = parse('init')
  expect(result).toBe(undefined)
  expect(mockReadLine.keyInYN).toHaveBeenCalledTimes(0)
  expect(mockGetLogger.mock.error).toHaveBeenCalledWith(
    expect.stringMatching(/Unable/),
  )

  delete mockFindUp.mock.syncFail
  delete mockReadLine.mock.keyInYNReturn
  delete mockFindUp.mock.syncReturn
})
github sezna / nps / src / bin-utils / __tests__ / parser.js View on Github external
() => {
    mockReadLine.mock.keyInYNReturn = true
    mockFindUp.mock.syncReturn = '/some/path/to/things'

    const result = parse('init foo.js')
    expect(result).toBe(undefined)
    expect(mockGetLogger.mock.info).toHaveBeenCalledWith(
      expect.stringMatching(/saved/),
    )

    delete mockReadLine.mock.keyInYNReturn
    delete mockFindUp.mock.syncReturn
  },
)
github sezna / nps / src / bin-utils / __tests__ / parser.js View on Github external
() => {
    mockReadLine.mock.keyInYNReturn = false
    mockFindUp.mock.syncReturn = '/some/path/to/things'

    const result = parse('init --config foo.js')
    expect(result).toBe(undefined)
    expect(mockReadLine.keyInYN).toHaveBeenCalledTimes(1)
    expect(mockReadLine.keyInYN).toHaveBeenCalledWith(
      expect.stringMatching(/overwrite.*file/),
    )
    expect(mockGetLogger.mock.info).toHaveBeenCalledTimes(1)
    expect(mockGetLogger.mock.info).toHaveBeenCalledWith(
      expect.stringMatching(/Exiting.*different/),
    )

    delete mockReadLine.mock.keyInYNReturn
    delete mockFindUp.mock.syncReturn
  },