-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathplugins.spec.ts
58 lines (51 loc) · 1.44 KB
/
plugins.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { mount, VueWrapper, config } from '../../src'
declare module '../../src/vue-wrapper' {
interface VueWrapper {
width(): number
$el: Element
}
}
const textValue = `I'm the innerHTML`
const mountComponent = () => mount({ template: `<h1>${textValue}</h1>` })
describe('Plugin', () => {
describe('#install method', () => {
beforeEach(() => {
config.plugins.VueWrapper.reset()
})
it('extends wrappers with the return values from the install function', () => {
const width = 230
const plugin = () => ({ width })
config.plugins.VueWrapper.install(plugin)
const wrapper = mountComponent()
expect(wrapper).toHaveProperty('width', width)
})
it('receives the wrapper inside the plugin setup', () => {
const plugin = (wrapper) => {
return {
$el: wrapper.element // simple aliases
}
}
config.plugins.VueWrapper.install(plugin)
const wrapper = mountComponent()
expect(wrapper.$el.innerHTML).toEqual(textValue)
})
describe('error states', () => {
const plugins = [
() => false,
() => true,
() => [],
true,
false,
'property',
120
]
it.each(plugins)(
'Calling install with %p is handled gracefully',
(plugin) => {
config.plugins.VueWrapper.install(plugin)
expect(() => mountComponent()).not.toThrow()
}
)
})
})
})