Skip to content

Commit 13100eb

Browse files
Исправляем установку таба при инициализации
1 parent 3818e5e commit 13100eb

File tree

6 files changed

+258
-152
lines changed

6 files changed

+258
-152
lines changed

packages/vuetify/src/components/VTabs/VTabs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export default baseMixins.extend({
204204
nextIcon: this.nextIcon,
205205
prevIcon: this.prevIcon,
206206
showArrows: this.showArrows,
207-
value: this.internalValue,
207+
modelValue: this.internalValue,
208208
'onCall:slider': this.callSlider,
209209
'onUpdate:modelValue': (val: any) => {
210210
this.internalValue = val

packages/vuetify/src/components/VTabs/__tests__/VTab.spec.ts

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ import VTab from '../VTab'
55
import {
66
mount,
77
RouterLinkStub,
8-
Wrapper,
8+
VueWrapper,
99
} from '@vue/test-utils'
1010

11-
// Types
12-
import { ExtractVue } from './../../../util/mixins'
13-
1411
describe('VTab.ts', () => {
15-
type Instance = ExtractVue<typeof VTab>
16-
let mountFunction: (options?: object) => Wrapper<Instance>
12+
type Instance = InstanceType<typeof VTab>
13+
let mountFunction: (options?: object) => VueWrapper<Instance>
1714

1815
beforeEach(() => {
1916
mountFunction = (options = {}) => {
@@ -23,48 +20,57 @@ describe('VTab.ts', () => {
2320
}
2421
})
2522

26-
it('should have the correct value', () => {
23+
it('should have the correct value', async () => {
2724
const wrapper = mountFunction({
28-
propsData: {
25+
props: {
2926
href: '#foo',
3027
},
31-
mocks: {
32-
$route: { path: '/' },
33-
$router: {
34-
resolve: to => {
35-
let href
36-
if (to.path) href = to.path
37-
38-
return { href }
28+
global: {
29+
mocks: {
30+
$route: { path: '/' },
31+
$router: {
32+
resolve: (to: any) => {
33+
let href
34+
if (to.path) href = to.path
35+
36+
return { href }
37+
},
3938
},
4039
},
40+
stubs: {
41+
'router-link': RouterLinkStub,
42+
},
4143
},
4244
})
4345

4446
expect(wrapper.vm.value).toBe('foo')
45-
wrapper.setProps({ href: null, to: '/foo' })
47+
await wrapper.setProps({ href: null, to: '/foo' })
4648
expect(wrapper.vm.value).toBe('/foo')
47-
wrapper.setProps({ to: { path: 'bar' } })
49+
await wrapper.setProps({ to: { path: 'bar' } })
4850
expect(wrapper.vm.value).toBe('bar')
4951
})
5052

5153
// Still unsure how to test actual implementation
5254
it('should react to route change', async () => {
5355
const toggle = jest.fn()
5456
const wrapper = mountFunction({
55-
propsData: {
57+
props: {
5658
activeClass: 'bar',
5759
to: 'foo',
5860
},
59-
methods: { toggle },
60-
mocks: {
61-
$route: { path: '/' },
62-
},
63-
stubs: {
64-
RouterLink: RouterLinkStub,
61+
global: {
62+
mocks: {
63+
$route: { path: '/' },
64+
},
65+
stubs: {
66+
'router-link': RouterLinkStub,
67+
},
6568
},
6669
})
6770

71+
// Mock the toggle method
72+
wrapper.vm.toggle = toggle
73+
6874
// Mock route change being called
6975
wrapper.vm.onRouteChange()
7076
await wrapper.vm.$nextTick()
@@ -73,42 +79,47 @@ describe('VTab.ts', () => {
7379

7480
// explicitly mock class added
7581
// by vue router
76-
;(wrapper.vm.$refs.link as any)._vnode.data = {
77-
class: { 'bar v-tab--active': true },
82+
if (wrapper.vm.$refs.link) {
83+
;(wrapper.vm.$refs.link as any)._vnode = {
84+
data: {
85+
class: { 'bar v-tab--active': true },
86+
}
87+
}
7888
}
7989
;(wrapper.vm as any).$route.path = '/foo'
8090

8191
wrapper.vm.onRouteChange()
8292
await wrapper.vm.$nextTick()
8393

84-
wrapper.setProps({ to: undefined })
94+
await wrapper.setProps({ to: undefined })
8595

8696
wrapper.vm.onRouteChange()
8797
await wrapper.vm.$nextTick()
8898

8999
expect(toggle).toHaveBeenCalledTimes(1)
90100
})
91101

92-
it('should respond to clicks and mousedown.enter', () => {
102+
it('should respond to clicks and mousedown.enter', async () => {
93103
const event = { preventDefault: jest.fn() }
94104
const toggle = jest.fn()
95-
const wrapper = mountFunction({
96-
methods: { toggle },
97-
})
105+
const wrapper = mountFunction()
106+
107+
// Mock the toggle method
108+
wrapper.vm.toggle = toggle
98109

99-
wrapper.trigger('click', event)
110+
await wrapper.trigger('click', event)
100111

101112
expect(event.preventDefault).not.toHaveBeenCalled()
102113
expect(toggle).toHaveBeenCalled()
103114

104-
wrapper.setProps({ href: '#foo' })
115+
await wrapper.setProps({ href: '#foo' })
105116

106-
wrapper.trigger('click', event)
117+
await wrapper.trigger('click', event)
107118

108119
expect(event.preventDefault).toHaveBeenCalled()
109120

110-
wrapper.trigger('keydown.enter', event)
111-
wrapper.trigger('keydown.space', event)
121+
await wrapper.trigger('keydown.enter', event)
122+
await wrapper.trigger('keydown.space', event)
112123

113124
expect(event.preventDefault).toHaveBeenCalledTimes(2)
114125
expect(toggle).toHaveBeenCalledTimes(3)

0 commit comments

Comments
 (0)