Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
gateway-proxy / usr / share / gateway-proxy / app / node_modules / furious-commander / test / error-handler.spec.ts
Size: Mime:
import cli, { LeafCommand } from '../src'

class TestCommand implements LeafCommand {
  public name = 'test'
  public description = 'Test'

  run() {
    throw Error('Expected')
  }
}

describe('Error handler', () => {
  it('should invoke custom error handler', async () => {
    let caughtError = null
    await cli({
      rootCommandClasses: [TestCommand],
      testArguments: ['test'],
      errorHandler: error => {
        caughtError = error
      },
    })
    expect(caughtError).toHaveProperty('message', 'Expected')
  })

  it('should invoke default error handler', async () => {
    let caughtError = null
    await cli({
      rootCommandClasses: [TestCommand],
      testArguments: ['test'],
      printer: {
        print: () => {
          /* empty */
        },
        printHeading: () => {
          /* empty */
        },
        formatDim: () => '',
        formatImportant: () => '',
        printError: message => {
          caughtError = message
        },
        getGenericErrorMessage: () => '',
      },
    })
    expect(caughtError).toBe('Expected')
  })
})