Skip to content

Commit 6990614

Browse files
author
Damian Dulisz
committed
1 parent a932fb2 commit 6990614

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

src/multiselectMixin.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,11 @@ module.exports = {
418418
adjustSearch () {
419419
if (!this.searchable || !this.clearOnSelect) return
420420

421-
this.search = this.multiple
422-
? ''
423-
: this.currentOptionLabel
421+
this.$nextTick(() => {
422+
this.search = this.multiple
423+
? ''
424+
: this.currentOptionLabel
425+
})
424426
},
425427
/**
426428
* Call this.activate() or this.deactivate()

test/unit/specs/Multiselect.spec.js

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@ describe('Multiselect.vue', () => {
261261
source: ['1', '2', '3']
262262
}
263263
}).$mount()
264-
expect(vm.$children[0].selected).to.deep.equal(vm.value)
265-
expect(vm.$children[0].$els.tags.querySelector('.multiselect__tag').textContent).to.contain('1')
264+
const comp = vm.$children[0]
265+
expect(comp.selected).to.deep.equal(vm.value)
266+
expect(comp.$els.tags.querySelector('.multiselect__tag').textContent).to.contain('1')
266267
})
267268

268269
it('should preselect passed array of objects', () => {
@@ -305,7 +306,7 @@ describe('Multiselect.vue', () => {
305306
})
306307

307308
describe('when multiple == FALSE', () => {
308-
it('should preselect passed simple value', () => {
309+
it('should preselect passed simple value', (done) => {
309310
const vm = new Vue({
310311
template: '<multiselect :selected="value" :options="source"></multiselect>',
311312
components: { Multiselect },
@@ -314,11 +315,17 @@ describe('Multiselect.vue', () => {
314315
source: ['1', '2', '3']
315316
}
316317
}).$mount()
317-
expect(vm.$children[0].selected).to.deep.equal(vm.value)
318-
expect(vm.$children[0].$els.tags.querySelector('input').value).to.contain('1')
318+
const comp = vm.$children[0]
319+
comp.$nextTick(() => {
320+
comp.$nextTick(() => {
321+
expect(comp.selected).to.deep.equal(vm.value)
322+
expect(comp.$els.tags.querySelector('input').value).to.contain('1')
323+
done()
324+
})
325+
})
319326
})
320327

321-
it('should preselect passed object', () => {
328+
it('should preselect passed object', (done) => {
322329
const vm = new Vue({
323330
template: '<multiselect :selected="value" :options="source" label="id" key="id"></multiselect>',
324331
components: { Multiselect },
@@ -327,8 +334,14 @@ describe('Multiselect.vue', () => {
327334
source: [{ id: '1' }, { id: '2' }, { id: '3' }]
328335
}
329336
}).$mount()
330-
expect(vm.$children[0].selected).to.deep.equal(vm.value)
331-
expect(vm.$children[0].$els.tags.querySelector('input').value).to.contain('2')
337+
const comp = vm.$children[0]
338+
comp.$nextTick(() => {
339+
comp.$nextTick(() => {
340+
expect(comp.selected).to.deep.equal(vm.value)
341+
expect(comp.$els.tags.querySelector('input').value).to.contain('2')
342+
done()
343+
})
344+
})
332345
})
333346

334347
it('should set value to null when passing null as selected', () => {
@@ -344,7 +357,7 @@ describe('Multiselect.vue', () => {
344357
expect(vm.$children[0].$els.tags.querySelector('.multiselect__tag')).to.equal(null)
345358
})
346359

347-
it('should set search value to equal to passed object label', () => {
360+
it('should set search value to equal to passed object label', (done) => {
348361
const vm = new Vue({
349362
template: '<multiselect :selected="value" :options="source" label="id" key="id"></multiselect>',
350363
components: { Multiselect },
@@ -353,11 +366,17 @@ describe('Multiselect.vue', () => {
353366
source: [{ id: '1' }, { id: '2' }, { id: '3' }]
354367
}
355368
}).$mount()
356-
expect(vm.$children[0].search).to.equal('1')
357-
expect(vm.$children[0].$els.search.value).to.equal('1')
369+
const comp = vm.$children[0]
370+
comp.$nextTick(() => {
371+
comp.$nextTick(() => {
372+
expect(comp.search).to.equal('1')
373+
expect(comp.$els.search.value).to.equal('1')
374+
done()
375+
})
376+
})
358377
})
359378

360-
it('should set search value to equal to passed value', () => {
379+
it('should set search value to equal to passed value', (done) => {
361380
const vm = new Vue({
362381
template: '<multiselect :selected="value" :options="source" label="id" key="id"></multiselect>',
363382
components: { Multiselect },
@@ -366,10 +385,16 @@ describe('Multiselect.vue', () => {
366385
source: [1, 2, 3]
367386
}
368387
}).$mount()
369-
expect(vm.$children[0].search).to.equal(2)
370-
expect(vm.$children[0].$els.search.value).to.equal('2')
388+
const comp = vm.$children[0]
389+
comp.$nextTick(() => {
390+
comp.$nextTick(() => {
391+
expect(comp.search).to.equal(2)
392+
expect(comp.$els.search.value).to.equal('2')
393+
done()
394+
})
395+
})
371396
})
372-
it('if selected is null should set search value to empty string', () => {
397+
it('if selected is null should set search value to empty string', (done) => {
373398
const vm = new Vue({
374399
template: '<multiselect :selected="value" :options="source" label="id" key="id" :taggable="true"></multiselect>',
375400
components: { Multiselect },
@@ -378,8 +403,14 @@ describe('Multiselect.vue', () => {
378403
source: [1, 2, 3]
379404
}
380405
}).$mount()
381-
expect(vm.$children[0].search).to.equal(null)
382-
expect(vm.$children[0].$els.search.value).to.equal('')
406+
const comp = vm.$children[0]
407+
comp.$nextTick(() => {
408+
comp.$nextTick(() => {
409+
expect(comp.search).to.equal(null)
410+
expect(comp.$els.search.value).to.equal('')
411+
done()
412+
})
413+
})
383414
})
384415
})
385416
})

0 commit comments

Comments
 (0)