Skip to content

Commit b5887ca

Browse files
authored
refactor(components): [page-header] use JSX in Unit test (element-plus#8263)
1 parent 04c9ee0 commit b5887ca

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

packages/components/page-header/__tests__/page-header.test.ts renamed to packages/components/page-header/__tests__/page-header.test.tsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,58 @@ const AXIOM = 'Rem is the best girl'
88

99
describe('PageHeader.vue', () => {
1010
test('render test', () => {
11-
const wrapper = mount(PageHeader, {
12-
props: { content: AXIOM },
13-
})
11+
const wrapper = mount(() => <PageHeader content={AXIOM} />)
1412
expect(wrapper.find('.el-page-header__content').text()).toEqual(AXIOM)
1513
})
1614

1715
test('should render icon props', () => {
1816
const icon = markRaw(ArrowLeft)
19-
const wrapper = mount(PageHeader, {
20-
props: { icon },
21-
})
17+
const wrapper = mount(() => <PageHeader icon={icon} />)
2218
expect(wrapper.findComponent(icon).exists()).toBe(true)
2319
})
2420

2521
test('should render icon slots', () => {
26-
const wrapper = mount(PageHeader, {
27-
slots: { icon: AXIOM },
28-
})
22+
const wrapper = mount(() => (
23+
<PageHeader
24+
v-slots={{
25+
icon: () => AXIOM,
26+
}}
27+
/>
28+
))
2929
expect(wrapper.find('.el-page-header__icon').text()).toEqual(AXIOM)
3030
})
3131

3232
test('slot content', () => {
33-
const wrapper = mount(PageHeader, {
34-
slots: { content: AXIOM },
35-
})
33+
const wrapper = mount(() => (
34+
<PageHeader
35+
v-slots={{
36+
content: () => AXIOM,
37+
}}
38+
/>
39+
))
3640
expect(wrapper.find('.el-page-header__content').text()).toEqual(AXIOM)
3741
})
3842

3943
test('prop title', () => {
40-
const wrapper = mount(PageHeader, {
41-
props: { title: AXIOM },
42-
})
44+
const wrapper = mount(() => <PageHeader title={AXIOM} />)
4345
expect(wrapper.find('.el-page-header__title').text()).toEqual(AXIOM)
4446
})
4547

4648
test('slot prop', () => {
47-
const wrapper = mount(PageHeader, {
48-
slots: { title: AXIOM },
49-
})
49+
const wrapper = mount(() => (
50+
<PageHeader
51+
v-slots={{
52+
title: () => AXIOM,
53+
}}
54+
/>
55+
))
5056
expect(wrapper.find('.el-page-header__title').text()).toEqual(AXIOM)
5157
})
5258

5359
test('event back', async () => {
54-
const wrapper = mount(PageHeader, {
55-
props: { content: AXIOM },
56-
})
57-
58-
await wrapper.find('.el-icon').trigger('click')
59-
expect(wrapper.emitted('back')).toBeDefined()
60+
const wrapper = mount(() => <PageHeader content={AXIOM} />)
61+
const pageHeader = wrapper.findComponent(PageHeader)
62+
await pageHeader.find('.el-icon').trigger('click')
63+
expect(pageHeader.emitted('back')).toBeDefined()
6064
})
6165
})

0 commit comments

Comments
 (0)