debian-mirror-gitlab/spec/frontend/vue_shared/components/slot_switch_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import { shallowMount } from '@vue/test-utils';
2023-06-20 00:43:36 +05:30
import { assertProps } from 'helpers/assert_props';
2019-12-26 22:10:19 +05:30
2020-03-13 15:44:24 +05:30
import SlotSwitch from '~/vue_shared/components/slot_switch.vue';
2019-12-26 22:10:19 +05:30
describe('SlotSwitch', () => {
const slots = {
first: '<a>AGP</a>',
second: '<p>PCI</p>',
};
let wrapper;
2021-03-08 18:12:59 +05:30
const createComponent = (propsData) => {
2019-12-26 22:10:19 +05:30
wrapper = shallowMount(SlotSwitch, {
propsData,
slots,
});
};
2021-03-08 18:12:59 +05:30
const getChildrenHtml = () => wrapper.findAll('* *').wrappers.map((c) => c.html());
2019-12-26 22:10:19 +05:30
it('throws an error if activeSlotNames is missing', () => {
2023-06-20 00:43:36 +05:30
expect(() => assertProps(SlotSwitch, {})).toThrow(
'[Vue warn]: Missing required prop: "activeSlotNames"',
);
2019-12-26 22:10:19 +05:30
});
it('renders no slots if activeSlotNames is empty', () => {
createComponent({
activeSlotNames: [],
});
expect(getChildrenHtml().length).toBe(0);
});
it('renders one slot if activeSlotNames contains single slot name', () => {
createComponent({
activeSlotNames: ['first'],
});
expect(getChildrenHtml()).toEqual([slots.first]);
});
it('renders multiple slots if activeSlotNames contains multiple slot names', () => {
createComponent({
activeSlotNames: Object.keys(slots),
});
expect(getChildrenHtml()).toEqual(Object.values(slots));
});
});