Skip to content

Commit 4e9545e

Browse files
test: add mixins test
1 parent 305fb1a commit 4e9545e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/config.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ describe('config', () => {
1212
mocks: undefined,
1313
provide: undefined
1414
}
15+
16+
jest.clearAllMocks()
1517
})
1618

1719
describe('components', () => {
@@ -105,4 +107,46 @@ describe('config', () => {
105107
).toEqual('baz')
106108
})
107109
})
110+
111+
describe('mixins', () => {
112+
const createdHook = jest.fn()
113+
const mixin = {
114+
created() {
115+
createdHook()
116+
}
117+
}
118+
const Component = {
119+
render() {
120+
return h('div')
121+
}
122+
}
123+
124+
it('sets a mixin everywhere', () => {
125+
config.global.mixins = [mixin]
126+
mount(Component)
127+
128+
// once on root, once in the mounted component
129+
expect(createdHook).toHaveBeenCalledTimes(2)
130+
})
131+
132+
it('concats with locally defined mixins', () => {
133+
config.global.mixins = [mixin]
134+
const localHook = jest.fn()
135+
const localMixin = {
136+
created() {
137+
localHook(this.$options.name)
138+
}
139+
}
140+
141+
mount(Component, {
142+
global: {
143+
mixins: [localMixin]
144+
}
145+
})
146+
147+
// once on root, once in the mounted component
148+
expect(localHook).toHaveBeenCalledTimes(2)
149+
expect(createdHook).toHaveBeenCalledTimes(2)
150+
})
151+
})
108152
})

0 commit comments

Comments
 (0)