inquirer-dynamic-list
Version:
A subclass of inquirer's list whose choices can be updated on the fly
73 lines (52 loc) • 1.88 kB
text/coffeescript
m = require('mochainon')
DynamicList = require('../lib/dynamic-list')
describe 'Dynamic List:', ->
describe 'given a list without choices', ->
beforeEach ->
= new DynamicList
message: 'Select an option'
choices: []
afterEach ->
.ui.close()
it 'should set a default emptyMessage', ->
m.chai.expect(.options.emptyMessage).to.equal('No options')
describe '#isEmpty()', ->
it 'should return true', ->
m.chai.expect(.isEmpty()).to.be.true
describe '#addChoice()', ->
it 'should be able to add a choice', ->
.addChoice(name: 'Foo', value: 'foo')
m.chai.expect(.opt.choices.length).to.equal(1)
m.chai.expect(.opt.choices.choices.length).to.equal(1)
m.chai.expect(.opt.choices.realChoices.length).to.equal(1)
m.chai.expect(.isEmpty()).to.be.false
describe 'given a list with a single choice', ->
beforeEach ->
= new DynamicList
message: 'Select an option'
choices: [
name: 'Foo'
value: 'foo'
]
afterEach ->
.ui.close()
describe '#isEmpty()', ->
it 'should return false', ->
m.chai.expect(.isEmpty()).to.be.false
describe '#removeChoice()', ->
it 'should be able to remove the choice', ->
.removeChoice(name: 'Foo', value: 'foo')
m.chai.expect(.opt.choices.length).to.equal(0)
m.chai.expect(.opt.choices.choices.length).to.equal(0)
m.chai.expect(.opt.choices.realChoices.length).to.equal(0)
m.chai.expect(.isEmpty()).to.be.true
describe 'given a list with an empty message', ->
beforeEach ->
= new DynamicList
message: 'Select an option'
emptyMessage: 'Nothing here'
choices: []
afterEach ->
.ui.close()
it 'should save the default emptyMessage', ->
m.chai.expect(.options.emptyMessage).to.equal('Nothing here')