|
1 | 1 | import { describe, expect, test, beforeEach, afterEach, vi } from 'vitest' |
2 | 2 | import { mount, VueWrapper } from '@vue/test-utils' |
3 | | -import { nextTick, PropType } from 'vue' |
| 3 | +import { nextTick, PropType, reactive } from 'vue' |
4 | 4 | import SlimSelect, { Option, Events } from '@/slim-select' |
5 | 5 | import SlimSelectVue from './vue.vue' |
6 | 6 |
|
@@ -556,6 +556,44 @@ describe('SlimSelect Vue Component', () => { |
556 | 556 | }) |
557 | 557 |
|
558 | 558 | describe('Reactivity Edge Cases', () => { |
| 559 | + test('mounts when data prop contains nested reactive option objects', async () => { |
| 560 | + const state = reactive({ |
| 561 | + items: [{ value: 'MLD', text: 'MLD' }] |
| 562 | + }) |
| 563 | + |
| 564 | + const TestComponent = { |
| 565 | + components: { SlimSelectVue }, |
| 566 | + template: ` |
| 567 | + <SlimSelectVue |
| 568 | + v-model="selected" |
| 569 | + :data="options" |
| 570 | + /> |
| 571 | + `, |
| 572 | + data() { |
| 573 | + return { |
| 574 | + selected: 'MLD' as string |
| 575 | + } |
| 576 | + }, |
| 577 | + computed: { |
| 578 | + options() { |
| 579 | + return [ |
| 580 | + { text: 'Select unit', value: '', placeholder: true }, |
| 581 | + ...state.items |
| 582 | + ] |
| 583 | + } |
| 584 | + } |
| 585 | + } |
| 586 | + |
| 587 | + const testWrapper = mount(TestComponent) |
| 588 | + await nextTick() |
| 589 | + |
| 590 | + const slimComponent = testWrapper.findComponent(SlimSelectVue) |
| 591 | + const slim = (slimComponent.vm as any).slim as SlimSelect |
| 592 | + expect(slim).toBeInstanceOf(SlimSelect) |
| 593 | + expect(slim.getSelected()).toEqual(['MLD']) |
| 594 | + testWrapper.unmount() |
| 595 | + }) |
| 596 | + |
559 | 597 | test('reactive data with v-model syncs without selected on options', async () => { |
560 | 598 | const TestComponent = { |
561 | 599 | components: { SlimSelectVue }, |
|
0 commit comments