Skip to content

Commit a5c69d5

Browse files
committed
test: Add tests cases for DpRoot component
1 parent 42131c8 commit a5c69d5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/packages/components/DpRoot/DpRoot.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
} from '@packages/types';
1414

1515
const props = {
16+
as: { type: String as PropType<string>, default: 'div' },
1617
modelValue: { type: [String, Date, Array, Object, Number] as PropType<ModelValueProp>, default: undefined },
1718
range: { type: [Boolean, Object] as PropType<RangeProp>, default: false },
1819
multiDates: { type: [Object, Boolean] as PropType<MultiDatesProp>, default: false },
@@ -43,6 +44,6 @@ export const DpRoot = {
4344
setup(props: DpRootProps, { slots, attrs, emit }: SetupContext) {
4445
useRoot(props, emit);
4546

46-
return () => h('div', { ...attrs }, slots.default?.());
47+
return () => h(props.as, { ...attrs }, slots.default?.());
4748
},
4849
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { mount } from '@vue/test-utils';
3+
import { DpRoot } from '@packages/components/DpRoot';
4+
5+
describe('DpRoot', () => {
6+
it('Should render component', () => {
7+
const wrapper = mount(DpRoot);
8+
9+
expect(wrapper.html()).toContain('<div>');
10+
});
11+
12+
it('Should render component as custom HTML tag', () => {
13+
const wrapper = mount(DpRoot, { props: { as: 'section' } });
14+
15+
expect(wrapper.html()).toContain('<section>');
16+
});
17+
});

0 commit comments

Comments
 (0)