-
Notifications
You must be signed in to change notification settings - Fork 668
/
Copy pathwrapper.spec.js
56 lines (44 loc) · 1.48 KB
/
wrapper.spec.js
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
import { describeWithShallowAndMount } from '~resources/utils'
import { enableAutoDestroy, resetAutoDestroyState } from '~vue/test-utils'
describeWithShallowAndMount('Wrapper', mountingMethod => {
;['vnode', 'element', 'vm', 'options'].forEach(property => {
it(`has the ${property} property which is read-only`, () => {
const wrapper = mountingMethod({ template: '<div><p></p></div>' }).find(
'p'
)
expect(wrapper.constructor.name).to.equal('Wrapper')
const message = `[vue-test-utils]: wrapper.${property} is read-only`
expect(() => {
wrapper[property] = 'foo'
})
.to.throw()
.with.property('message', message)
})
})
describe('enableAutoDestroy', () => {
const sandbox = sinon.createSandbox()
beforeEach(() => {
resetAutoDestroyState()
})
it('calls the hook function', () => {
const hookSpy = sandbox.spy()
enableAutoDestroy(hookSpy)
expect(hookSpy).calledOnce
})
it('uses the hook function to destroy wrappers', () => {
let hookCallback
enableAutoDestroy(callback => {
hookCallback = callback
})
const wrapper = mountingMethod({ template: '<p>con tent</p>' })
sandbox.spy(wrapper, 'destroy')
hookCallback()
expect(wrapper.destroy).calledOnce
})
it('cannot be called twice', () => {
const noop = () => {}
enableAutoDestroy(noop)
expect(() => enableAutoDestroy(noop)).to.throw()
})
})
})