Skip to content

Commit 974be4f

Browse files
committed
throw error
1 parent 5950f50 commit 974be4f

File tree

8 files changed

+32
-31
lines changed

8 files changed

+32
-31
lines changed

Diff for: packages/test-utils/src/vue-wrapper.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22

33
import Wrapper from './wrapper'
4+
import { throwError } from 'shared/util'
45
import { setWatchersToSync } from './set-watchers-to-sync'
56
import { orderWatchers } from './order-watchers'
67

@@ -11,17 +12,17 @@ export default class VueWrapper extends Wrapper implements BaseWrapper {
1112
// $FlowIgnore : issue with defineProperty
1213
Object.defineProperty(this, 'vnode', {
1314
get: () => vm._vnode,
14-
set: () => {}
15+
set: () => throwError(`VueWrapper.vnode is read-only`)
1516
})
1617
// $FlowIgnore
1718
Object.defineProperty(this, 'element', {
1819
get: () => vm.$el,
19-
set: () => {}
20+
set: () => throwError(`VueWrapper.element is read-only`)
2021
})
2122
// $FlowIgnore
2223
Object.defineProperty(this, 'vm', {
2324
get: () => vm,
24-
set: () => {}
25+
set: () => throwError(`VueWrapper.vm is read-only`)
2526
})
2627
if (options.sync) {
2728
setWatchersToSync(vm)

Diff for: packages/test-utils/src/wrapper-array.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export default class WrapperArray implements BaseWrapper {
1313
// $FlowIgnore
1414
Object.defineProperty(this, 'wrappers', {
1515
get: () => wrappers,
16-
set: () => {}
16+
set: () => throwError(`WrapperArray.wrappers is read-only`)
1717
})
1818
// $FlowIgnore
1919
Object.defineProperty(this, 'length', {
2020
get: () => length,
21-
set: () => {}
21+
set: () => throwError(`WrapperArray.length is read-only`)
2222
})
2323
}
2424

Diff for: packages/test-utils/src/wrapper.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { orderWatchers } from './order-watchers'
2424

2525
export default class Wrapper implements BaseWrapper {
2626
+vnode: VNode | null;
27+
_vnode: VNode | null;
2728
+vm: Component | null;
2829
_emitted: { [name: string]: Array<Array<any>> };
2930
_emittedByOrder: Array<{ name: string, args: Array<any> }>;
@@ -39,27 +40,28 @@ export default class Wrapper implements BaseWrapper {
3940
const element = node instanceof Element ? node : node.elm
4041
// Prevent redefine by VueWrapper
4142
if (this.constructor.name === 'Wrapper') {
43+
this._vnode = vnode
4244
// $FlowIgnore
4345
Object.defineProperty(this, 'vnode', {
44-
get: () => vnode,
45-
set: () => {}
46+
get: () => this._vnode,
47+
set: () => throwError(`Wrapper.vnode is read-only`)
4648
})
4749
// $FlowIgnore
4850
Object.defineProperty(this, 'element', {
4951
get: () => element,
50-
set: () => {}
52+
set: () => throwError(`Wrapper.element is read-only`)
5153
})
5254
// $FlowIgnore
5355
Object.defineProperty(this, 'vm', {
5456
get: () => undefined,
55-
set: () => {}
57+
set: () => throwError(`Wrapper.vm is read-only`)
5658
})
5759
}
5860
const frozenOptions = Object.freeze(options)
5961
// $FlowIgnore
6062
Object.defineProperty(this, 'options', {
6163
get: () => frozenOptions,
62-
set: () => {}
64+
set: () => throwError(`${this.constructor.name}.options is read-only`)
6365
})
6466
if (
6567
this.vnode &&
@@ -399,7 +401,6 @@ export default class Wrapper implements BaseWrapper {
399401
}
400402

401403
return !!(
402-
this.element &&
403404
this.element.getAttribute &&
404405
this.element.matches(selector)
405406
)
@@ -667,7 +668,7 @@ export default class Wrapper implements BaseWrapper {
667668
})
668669

669670
// $FlowIgnore : Problem with possibly null this.vm
670-
this.vnode = this.vm._vnode
671+
this._vnode = this.vm._vnode
671672
orderWatchers(this.vm || this.vnode.context.$root)
672673
Vue.config.silent = originalConfig
673674
}

Diff for: test/specs/vuewrapper.js renamed to test/specs/vue-wrapper.spec.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ describeWithShallowAndMount('VueWrapper', mountingMethod => {
55
it(`has the ${property} property which is read-only`, () => {
66
const wrapper = mountingMethod({ template: '<div><p></p></div>' })
77
expect(wrapper.constructor.name).to.equal('VueWrapper')
8-
const originalProperty = wrapper[property]
9-
wrapper[property] = 'foo'
10-
expect(wrapper[property]).to.equal(originalProperty)
8+
const message = `[vue-test-utils]: VueWrapper.${property} is read-only`
9+
expect(() => { wrapper[property] = 'foo' })
10+
.to.throw()
11+
.with.property('message', message)
1112
})
1213
})
1314
})

Diff for: test/specs/wrapper-array.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ describeWithShallowAndMount('WrapperArray', mountingMethod => {
1010
return wrappers ? new wrapperArray.constructor(wrappers) : wrapperArray
1111
}
1212

13+
['wrappers', 'length'].forEach(property => {
14+
it(`has the ${property} property which is read-only`, () => {
15+
const wrapperArray = getWrapperArray()
16+
const message = `[vue-test-utils]: WrapperArray.${property} is read-only`
17+
expect(() => { wrapperArray[property] = 'foo' })
18+
.to.throw()
19+
.with.property('message', message)
20+
})
21+
})
22+
1323
it('returns class with length equal to length of wrappers passed in constructor', () => {
1424
const wrapperArray = getWrapperArray()
1525
expect(wrapperArray.length).to.equal(3)

Diff for: test/specs/wrapper.spec.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ describeWithShallowAndMount('Wrapper', mountingMethod => {
66
const wrapper = mountingMethod({ template: '<div><p></p></div>' })
77
.find('p')
88
expect(wrapper.constructor.name).to.equal('Wrapper')
9-
const originalProperty = wrapper[property]
10-
wrapper[property] = 'foo'
11-
expect(wrapper[property]).to.equal(originalProperty)
9+
const message = `[vue-test-utils]: Wrapper.${property} is read-only`
10+
expect(() => { wrapper[property] = 'foo' })
11+
.to.throw()
12+
.with.property('message', message)
1213
})
1314
})
1415
})

Diff for: test/specs/wrapper/attributes.spec.js

-7
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,4 @@ describeWithShallowAndMount('attributes', mountingMethod => {
1515
const wrapper = mountingMethod(compiled)
1616
expect(wrapper.attributes()).to.eql({})
1717
})
18-
19-
it('returns empty object if wrapper element is null', () => {
20-
const compiled = compileToFunctions('<div />')
21-
const wrapper = mountingMethod(compiled)
22-
wrapper.element = null
23-
expect(wrapper.attributes()).to.eql({})
24-
})
2518
})

Diff for: test/specs/wrapper/is.spec.js

-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ describeWithShallowAndMount('is', mountingMethod => {
2828
expect(wrapper.is('#div')).to.equal(true)
2929
})
3030

31-
it('returns false if wrapper does not contain element', () => {
32-
const wrapper = mountingMethod(ComponentWithChild)
33-
wrapper.element = null
34-
expect(wrapper.is('a')).to.equal(false)
35-
})
36-
3731
it('returns true if root node matches Vue Component selector', () => {
3832
const wrapper = mountingMethod(ComponentWithChild)
3933
const component = wrapper.findAll(Component).at(0)

0 commit comments

Comments
 (0)