Skip to content

Commit

Permalink
Add test for component to emit the correct value as array
Browse files Browse the repository at this point in the history
  • Loading branch information
cnotv committed Oct 4, 2024
1 parent 55e3f1f commit 1fba36c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions shell/components/form/__tests__/LabeledSelect.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from '@vue/test-utils';
import LabeledSelect from '@shell/components/form/LabeledSelect.vue';
import { defineComponent } from 'vue';

describe('component: LabeledSelect', () => {
describe('should display correct label', () => {
Expand Down Expand Up @@ -135,4 +136,45 @@ describe('component: LabeledSelect', () => {
});
});
});

describe('given attributes from parent element', () => {
it('should not pass classes to the select element', () => {
const customClass = 'bananas';
const ParentComponent = defineComponent({
components: { LabeledSelect },
template: `<LabeledSelect class="${ customClass }" />`,
});
const wrapper = mount(ParentComponent);
const input = wrapper.find('.v-select');

expect(input.classes).not.toContain(customClass);
});

it.each([
[true, ['bananas']],
[false, 'bananas'],
])('given multiple as %p, should emit %p', async(multiple, expectation) => {
const ParentComponent = defineComponent({
components: { LabeledSelect },
template: `
<LabeledSelect
v-model:value="myValue"
:multiple="${ multiple }"
:options="options"
:appendToBody="false"
/>`,
data: () => ({
myValue: [],
options: ['bananas']
})
});
const wrapper = mount(ParentComponent);

// https://test-utils.vuejs.org/guide/essentials/event-handling#Asserting-the-arguments-of-the-event
await wrapper.find('input').trigger('focus');
await wrapper.find('.vs__dropdown-option').trigger('click');

expect(wrapper.vm.$data.myValue).toStrictEqual(expectation);
});
});
});

0 comments on commit 1fba36c

Please sign in to comment.