Skip to content

Working around sinon unable to stub ES modules #497

@kurtaking

Description

@kurtaking

I am trying to test a command that leverages @inquirer/prompts, and cannot figure out how to stub the input prompt.

Here is my test

import * as prompts from '@inquirer/prompts'
import {expect, test} from '@oclif/test'

import New from '../../../src/commands/config/new'

describe('config:new', () => {
  test
    .stdout({print: true})
    .stub(prompts, 'input', (stub) => stub.onFirstCall().resolves('First Last'))
    .do(() => New.run([]))
    .it('runs config:new', (ctx) => {
      expect(ctx.stdout).to.contain('Hello First!')
    })
})

I receive the following error on the .stub call.

 TypeError: ES Modules cannot be stubbed

Does anyone have a workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions