🌐 AI搜索 & 代理 主页
Skip to content

Commit 8ce291b

Browse files
committed
chore(compat): refactor tests not to use $children
1 parent 6683001 commit 8ce291b

File tree

4 files changed

+45
-47
lines changed

4 files changed

+45
-47
lines changed

src/components/dropdown/dropdown-item.spec.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ describe('dropdown-item', () => {
116116
h(BDropdownItem, { props: { href: '/a' } }, ['href-a']),
117117
// <router-link>
118118
h(BDropdownItem, { props: { to: { path: '/b' } } }, ['to-path-b']),
119-
// Regular link
120-
h(BDropdownItem, { props: { href: '/b' } }, ['href-a']),
121119
h('router-view')
122120
])
123121
}
@@ -130,28 +128,18 @@ describe('dropdown-item', () => {
130128
expect(wrapper.vm).toBeDefined()
131129
expect(wrapper.element.tagName).toBe('UL')
132130

133-
expect(wrapper.findAll('li').length).toBe(4)
134-
expect(wrapper.findAll('a').length).toBe(4)
131+
expect(wrapper.findAll('li').length).toBe(3)
132+
expect(wrapper.findAll('a').length).toBe(3)
135133

136134
const $links = wrapper.findAllComponents('a')
137135

138-
expect($links.at(0).vm).toBeDefined()
139-
expect($links.at(0).vm.$options.name).toBe('BLink')
140-
expect($links.at(0).vm.$children.length).toBe(1)
141-
expect($links.at(0).vm.$children[0].$options.name).toBe('RouterLink')
142-
143-
expect($links.at(1).vm).toBeDefined()
144-
expect($links.at(1).vm.$options.name).toBe('BLink')
145-
expect($links.at(1).vm.$children.length).toBe(0)
146-
147-
expect($links.at(2).vm).toBeDefined()
148-
expect($links.at(2).vm.$options.name).toBe('BLink')
149-
expect($links.at(2).vm.$children.length).toBe(1)
150-
expect($links.at(2).vm.$children[0].$options.name).toBe('RouterLink')
151-
152-
expect($links.at(3).vm).toBeDefined()
153-
expect($links.at(3).vm.$options.name).toBe('BLink')
154-
expect($links.at(3).vm.$children.length).toBe(0)
136+
$links.wrappers.forEach($link => {
137+
expect($link.vm).toBeDefined()
138+
expect($links.at(0).vm.$options.name).toBe('BLink')
139+
})
140+
expect(
141+
$links.wrappers.map($link => $link.findComponent({ name: 'RouterLink' }).exists())
142+
).toStrictEqual([true, false, true])
155143

156144
wrapper.destroy()
157145
})

src/components/link/link.spec.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,6 @@ describe('b-link', () => {
395395
h('b-link', { props: { href: '/a' } }, ['href-a']),
396396
// router-link
397397
h('b-link', { props: { to: { path: '/b' } } }, ['to-path-b']),
398-
// regular link
399-
h('b-link', { props: { href: '/b' } }, ['href-a']),
400398
// g-link
401399
h('b-link', { props: { routerComponentName: 'g-link', to: '/a' } }, ['g-link-a']),
402400
h('router-view')
@@ -412,32 +410,23 @@ describe('b-link', () => {
412410
expect(wrapper.vm).toBeDefined()
413411
expect(wrapper.element.tagName).toBe('MAIN')
414412

415-
expect(wrapper.findAll('a').length).toBe(5)
413+
expect(wrapper.findAll('a').length).toBe(4)
416414

417415
const $links = wrapper.findAllComponents('a')
418-
419-
expect($links.at(0).vm).toBeDefined()
420-
expect($links.at(0).vm.$options.name).toBe('BLink')
421-
expect($links.at(0).vm.$children.length).toBe(1)
422-
expect($links.at(0).vm.$children[0].$options.name).toBe('RouterLink')
423-
424-
expect($links.at(1).vm).toBeDefined()
425-
expect($links.at(1).vm.$options.name).toBe('BLink')
426-
expect($links.at(1).vm.$children.length).toBe(0)
427-
428-
expect($links.at(2).vm).toBeDefined()
429-
expect($links.at(2).vm.$options.name).toBe('BLink')
430-
expect($links.at(2).vm.$children.length).toBe(1)
431-
expect($links.at(2).vm.$children[0].$options.name).toBe('RouterLink')
432-
433-
expect($links.at(3).vm).toBeDefined()
434-
expect($links.at(3).vm.$options.name).toBe('BLink')
435-
expect($links.at(3).vm.$children.length).toBe(0)
436-
437-
expect($links.at(4).vm).toBeDefined()
438-
expect($links.at(4).vm.$options.name).toBe('BLink')
439-
expect($links.at(4).vm.$children.length).toBe(1)
440-
expect($links.at(4).vm.$children[0].$options.name).toBe('GLink')
416+
$links.wrappers.forEach($link => {
417+
expect($link.vm).toBeDefined()
418+
expect($links.at(0).vm.$options.name).toBe('BLink')
419+
})
420+
expect(
421+
$links.wrappers.map($link => $link.findComponent({ name: 'RouterLink' }).exists())
422+
).toStrictEqual([true, false, true, false])
423+
424+
expect(
425+
$links
426+
.at(3)
427+
.findComponent(GLink)
428+
.exists()
429+
).toBe(true)
441430

442431
wrapper.destroy()
443432
})

src/components/pagination-nav/pagination-nav.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ describe('pagination-nav', () => {
408408

409409
it('clicking buttons updates the v-model', async () => {
410410
const App = {
411+
compatConfig: { MODE: 3, RENDER_FUNCTION: 'suppress-warning' },
411412
methods: {
412413
onPageClick(bvEvent, page) {
413414
// Prevent 3rd page from being selected
@@ -543,6 +544,7 @@ describe('pagination-nav', () => {
543544

544545
it('works with $router to detect path and linkGen returns location object', async () => {
545546
const App = {
547+
compatConfig: { MODE: 3, COMPONENT_FUNCTIONAL: 'suppress-warning' },
546548
components: { BPaginationNav },
547549
methods: {
548550
linkGen(page) {
@@ -561,6 +563,7 @@ describe('pagination-nav', () => {
561563
}
562564
// Our router view component
563565
const FooRoute = {
566+
compatConfig: { MODE: 3, RENDER_FUNCTION: 'suppress-warning' },
564567
render(h) {
565568
return h('div', { class: 'foo-content' }, ['stub'])
566569
}
@@ -604,6 +607,7 @@ describe('pagination-nav', () => {
604607

605608
it('works with $router to detect path and use-router set and linkGen returns string', async () => {
606609
const App = {
610+
compatConfig: { MODE: 3, COMPONENT_FUNCTIONAL: 'suppress-warning' },
607611
components: { BPaginationNav },
608612
methods: {
609613
linkGen(page) {
@@ -622,6 +626,7 @@ describe('pagination-nav', () => {
622626
}
623627
// Our router view component
624628
const FooRoute = {
629+
compatConfig: { MODE: 3, RENDER_FUNCTION: 'suppress-warning' },
625630
render(h) {
626631
return h('div', { class: 'foo-content' }, ['stub'])
627632
}

src/mixins/listeners.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { listenersMixin } from './listeners'
66
describe('mixins > listeners', () => {
77
it('works', async () => {
88
const BTest = {
9+
compatConfig: {
10+
MODE: 3,
11+
RENDER_FUNCTION: 'suppress-warning',
12+
INSTANCE_LISTENERS: 'suppress-warning'
13+
},
914
name: 'BTest',
1015
mixins: [listenersMixin],
1116
inheritAttrs: false,
@@ -14,6 +19,7 @@ describe('mixins > listeners', () => {
1419
}
1520
}
1621
const App = {
22+
compatConfig: { MODE: 3, RENDER_FUNCTION: 'suppress-warning' },
1723
name: 'App',
1824
props: ['listenClick', 'listenFocus', 'listenBlur'],
1925
computed: {
@@ -91,6 +97,11 @@ describe('mixins > listeners', () => {
9197
let input2RenderCount = 0
9298

9399
const Input1 = {
100+
compatConfig: {
101+
MODE: 3,
102+
RENDER_FUNCTION: 'suppress-warning',
103+
INSTANCE_LISTENERS: 'suppress-warning'
104+
},
94105
props: ['value'],
95106
render(h) {
96107
input1RenderCount++
@@ -102,6 +113,11 @@ describe('mixins > listeners', () => {
102113
}
103114
}
104115
const Input2 = {
116+
compatConfig: {
117+
MODE: 3,
118+
RENDER_FUNCTION: 'suppress-warning',
119+
INSTANCE_LISTENERS: 'suppress-warning'
120+
},
105121
props: ['value'],
106122
mixins: [listenersMixin],
107123
render(h) {

0 commit comments

Comments
 (0)