Skip to content

Commit 1d1d003

Browse files
authored
refactor: remove deprecated methods (#1109)
BREAKING CHANGE: hasStyle, hasAttribute, hasClass, hasProp, visible, and setComputed removed
1 parent 1f160df commit 1d1d003

18 files changed

+4
-960
lines changed

Diff for: flow/wrapper.flow.js

-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ declare interface BaseWrapper {
1818
emittedByOrder(): Array<{ name: string, args: Array<any> }> | void;
1919
exists(): boolean;
2020
filter(predicate: Function): WrapperArray | void;
21-
visible(): boolean | void;
22-
hasAttribute(attribute: string, value: string): boolean | void;
23-
hasClass(className: string): boolean | void;
24-
hasProp(prop: string, value: string): boolean | void;
25-
hasStyle(style: string, value: string): boolean | void;
2621
find(selector: Selector): Wrapper | void;
2722
findAll(selector: Selector): WrapperArray | void;
2823
html(): string | void;
@@ -34,7 +29,6 @@ declare interface BaseWrapper {
3429
props(key?: string): { [name: string]: any } | any | void;
3530
text(): string | void;
3631
setData(data: Object): void;
37-
setComputed(computed: Object): void;
3832
setMethods(methods: Object): void;
3933
setValue(value: any): void;
4034
setChecked(checked?: boolean): void;

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

-38
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ export default class WrapperArray implements BaseWrapper {
6161
return new WrapperArray(this.wrappers.filter(predicate))
6262
}
6363

64-
visible (): boolean {
65-
this.throwErrorIfWrappersIsEmpty('visible')
66-
67-
return this.length > 0 && this.wrappers.every(wrapper => wrapper.visible())
68-
}
69-
7064
emitted (): void {
7165
this.throwErrorIfWrappersIsEmpty('emitted')
7266

@@ -85,32 +79,6 @@ export default class WrapperArray implements BaseWrapper {
8579
)
8680
}
8781

88-
hasAttribute (attribute: string, value: string): boolean {
89-
this.throwErrorIfWrappersIsEmpty('hasAttribute')
90-
91-
return this.wrappers.every(wrapper =>
92-
wrapper.hasAttribute(attribute, value)
93-
)
94-
}
95-
96-
hasClass (className: string): boolean {
97-
this.throwErrorIfWrappersIsEmpty('hasClass')
98-
99-
return this.wrappers.every(wrapper => wrapper.hasClass(className))
100-
}
101-
102-
hasProp (prop: string, value: string): boolean {
103-
this.throwErrorIfWrappersIsEmpty('hasProp')
104-
105-
return this.wrappers.every(wrapper => wrapper.hasProp(prop, value))
106-
}
107-
108-
hasStyle (style: string, value: string): boolean {
109-
this.throwErrorIfWrappersIsEmpty('hasStyle')
110-
111-
return this.wrappers.every(wrapper => wrapper.hasStyle(style, value))
112-
}
113-
11482
findAll (): void {
11583
this.throwErrorIfWrappersIsEmpty('findAll')
11684

@@ -195,12 +163,6 @@ export default class WrapperArray implements BaseWrapper {
195163
}
196164
}
197165

198-
setComputed (computed: Object): void {
199-
this.throwErrorIfWrappersIsEmpty('setComputed')
200-
201-
this.wrappers.forEach(wrapper => wrapper.setComputed(computed))
202-
}
203-
204166
setData (data: Object): void {
205167
this.throwErrorIfWrappersIsEmpty('setData')
206168

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

-230
Original file line numberDiff line numberDiff line change
@@ -234,139 +234,6 @@ export default class Wrapper implements BaseWrapper {
234234
return new WrapperArray(wrappers)
235235
}
236236

237-
/**
238-
* Checks if wrapper has an attribute with matching value
239-
*/
240-
hasAttribute (attribute: string, value: string): boolean {
241-
warn(
242-
`hasAttribute() has been deprecated and will be ` +
243-
`removed in version 1.0.0. Use attributes() ` +
244-
`instead—https://vue-test-utils.vuejs.org/api/wrapper/attributes.html`
245-
)
246-
247-
if (typeof attribute !== 'string') {
248-
throwError(
249-
`wrapper.hasAttribute() must be passed attribute as a string`
250-
)
251-
}
252-
253-
if (typeof value !== 'string') {
254-
throwError(
255-
`wrapper.hasAttribute() must be passed value as a string`
256-
)
257-
}
258-
259-
return !!(this.element.getAttribute(attribute) === value)
260-
}
261-
262-
/**
263-
* Asserts wrapper has a class name
264-
*/
265-
hasClass (className: string): boolean {
266-
warn(
267-
`hasClass() has been deprecated and will be removed ` +
268-
`in version 1.0.0. Use classes() ` +
269-
`instead—https://vue-test-utils.vuejs.org/api/wrapper/classes.html`
270-
)
271-
let targetClass = className
272-
273-
if (typeof targetClass !== 'string') {
274-
throwError('wrapper.hasClass() must be passed a string')
275-
}
276-
277-
// if $style is available and has a matching target, use that instead.
278-
if (this.vm && this.vm.$style && this.vm.$style[targetClass]) {
279-
targetClass = this.vm.$style[targetClass]
280-
}
281-
282-
const containsAllClasses = targetClass
283-
.split(' ')
284-
.every(target => this.element.classList.contains(target))
285-
286-
return !!(this.element && containsAllClasses)
287-
}
288-
289-
/**
290-
* Asserts wrapper has a prop name
291-
*/
292-
hasProp (prop: string, value: string): boolean {
293-
warn(
294-
`hasProp() has been deprecated and will be removed ` +
295-
`in version 1.0.0. Use props() ` +
296-
`instead—https://vue-test-utils.vuejs.org/api/wrapper/props.html`
297-
)
298-
299-
if (!this.isVueInstance()) {
300-
throwError('wrapper.hasProp() must be called on a Vue instance')
301-
}
302-
if (typeof prop !== 'string') {
303-
throwError('wrapper.hasProp() must be passed prop as a string')
304-
}
305-
306-
// $props object does not exist in Vue 2.1.x, so use
307-
// $options.propsData instead
308-
if (
309-
this.vm &&
310-
this.vm.$options &&
311-
this.vm.$options.propsData &&
312-
this.vm.$options.propsData[prop] === value
313-
) {
314-
return true
315-
}
316-
317-
return !!this.vm && !!this.vm.$props && this.vm.$props[prop] === value
318-
}
319-
320-
/**
321-
* Checks if wrapper has a style with value
322-
*/
323-
hasStyle (style: string, value: string): boolean {
324-
warn(
325-
`hasStyle() has been deprecated and will be removed ` +
326-
`in version 1.0.0. Use wrapper.element.style ` +
327-
`instead`
328-
)
329-
330-
if (typeof style !== 'string') {
331-
throwError(`wrapper.hasStyle() must be passed style as a string`)
332-
}
333-
334-
if (typeof value !== 'string') {
335-
throwError('wrapper.hasClass() must be passed value as string')
336-
}
337-
338-
/* istanbul ignore next */
339-
if (
340-
navigator.userAgent.includes &&
341-
(navigator.userAgent.includes('node.js') ||
342-
navigator.userAgent.includes('jsdom'))
343-
) {
344-
warn(
345-
`wrapper.hasStyle is not fully supported when ` +
346-
`running jsdom - only inline styles are supported`
347-
)
348-
}
349-
const body = document.querySelector('body')
350-
const mockElement = document.createElement('div')
351-
352-
if (!(body instanceof Element)) {
353-
return false
354-
}
355-
const mockNode = body.insertBefore(mockElement, null)
356-
// $FlowIgnore : Flow thinks style[style] returns a number
357-
mockElement.style[style] = value
358-
359-
if (!this.options.attachedToDocument && (this.vm || this.vnode)) {
360-
// $FlowIgnore : Possible null value, will be removed in 1.0.0
361-
const vm = this.vm || this.vnode.context.$root
362-
body.insertBefore(vm.$root._vnode.elm, null)
363-
}
364-
365-
const elStyle = window.getComputedStyle(this.element)[style]
366-
const mockNodeStyle = window.getComputedStyle(mockNode)[style]
367-
return !!(elStyle && mockNodeStyle && elStyle === mockNodeStyle)
368-
}
369-
370237
/**
371238
* Returns HTML of element as a string
372239
*/
@@ -562,79 +429,6 @@ export default class Wrapper implements BaseWrapper {
562429
throwError(`wrapper.setSelected() cannot be called on this element`)
563430
}
564431

565-
/**
566-
* Sets vm computed
567-
*/
568-
setComputed (computed: Object): void {
569-
if (!this.isVueInstance()) {
570-
throwError(
571-
`wrapper.setComputed() can only be called on a Vue ` +
572-
`instance`
573-
)
574-
}
575-
576-
warn(
577-
`setComputed() has been deprecated and will be ` +
578-
`removed in version 1.0.0. You can overwrite ` +
579-
`computed properties by passing a computed object ` +
580-
`in the mounting options`
581-
)
582-
583-
Object.keys(computed).forEach(key => {
584-
if (VUE_VERSION > 2.1) {
585-
// $FlowIgnore : Problem with possibly null this.vm
586-
if (!this.vm._computedWatchers[key]) {
587-
throwError(
588-
`wrapper.setComputed() was passed a value that ` +
589-
`does not exist as a computed property on the ` +
590-
`Vue instance. Property ${key} does not exist ` +
591-
`on the Vue instance`
592-
)
593-
}
594-
// $FlowIgnore : Problem with possibly null this.vm
595-
this.vm._computedWatchers[key].value = computed[key]
596-
// $FlowIgnore : Problem with possibly null this.vm
597-
this.vm._computedWatchers[key].getter = () => computed[key]
598-
} else {
599-
let isStore = false
600-
// $FlowIgnore : Problem with possibly null this.vm
601-
this.vm._watchers.forEach(watcher => {
602-
if (watcher.getter.vuex && key in watcher.vm.$options.store.getters) {
603-
watcher.vm.$options.store.getters = {
604-
...watcher.vm.$options.store.getters
605-
}
606-
Object.defineProperty(watcher.vm.$options.store.getters, key, {
607-
get: function () {
608-
return computed[key]
609-
}
610-
})
611-
isStore = true
612-
}
613-
})
614-
615-
// $FlowIgnore : Problem with possibly null this.vm
616-
if (!isStore && !this.vm._watchers.some(w => w.getter.name === key)) {
617-
throwError(
618-
`wrapper.setComputed() was passed a value that does ` +
619-
`not exist as a computed property on the Vue instance. ` +
620-
`Property ${key} does not exist on the Vue instance`
621-
)
622-
}
623-
// $FlowIgnore : Problem with possibly null this.vm
624-
this.vm._watchers.forEach(watcher => {
625-
if (watcher.getter.name === key) {
626-
watcher.value = computed[key]
627-
watcher.getter = () => computed[key]
628-
}
629-
})
630-
}
631-
})
632-
// $FlowIgnore : Problem with possibly null this.vm
633-
this.vm._watchers.forEach(watcher => {
634-
watcher.run()
635-
})
636-
}
637-
638432
/**
639433
* Sets vm data
640434
*/
@@ -830,28 +624,4 @@ export default class Wrapper implements BaseWrapper {
830624
`updates are now synchronous by default`
831625
)
832626
}
833-
834-
/**
835-
* Utility to check wrapper is visible. Returns false if a parent
836-
* element has display: none or visibility: hidden style.
837-
*/
838-
visible (): boolean {
839-
warn(
840-
`visible has been deprecated and will be removed in ` +
841-
`version 1, use isVisible instead`
842-
)
843-
let element = this.element
844-
while (element) {
845-
if (
846-
element.style &&
847-
(element.style.visibility === 'hidden' ||
848-
element.style.display === 'none')
849-
) {
850-
return false
851-
}
852-
element = element.parentElement
853-
}
854-
855-
return true
856-
}
857627
}

Diff for: packages/test-utils/types/index.d.ts

-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ interface BaseWrapper {
5353
contains (selector: Selector): boolean
5454
exists (): boolean
5555
isVisible (): boolean
56-
visible (): boolean
5756

5857
attributes(): { [name: string]: string }
5958
attributes(key: string): string | void
@@ -62,16 +61,10 @@ interface BaseWrapper {
6261
props(): { [name: string]: any }
6362
props(key: string): any | void
6463

65-
hasAttribute (attribute: string, value: string): boolean
66-
hasClass (className: string): boolean
67-
hasProp (prop: string, value: any): boolean
68-
hasStyle (style: string, value: string): boolean
69-
7064
is (selector: Selector): boolean
7165
isEmpty (): boolean
7266
isVueInstance (): boolean
7367

74-
setComputed (computed: object): void
7568
setData (data: object): void
7669
setMethods (data: object): void
7770
setProps (props: object): void

Diff for: packages/test-utils/types/test/wrapper.ts

-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ bool = wrapper.contains(ClassComponent)
1313

1414
bool = wrapper.exists()
1515

16-
bool = wrapper.hasAttribute('foo', 'bar')
1716
bool = wrapper.attributes().foo === 'bar'
18-
bool = wrapper.hasClass('foo-class')
19-
bool = wrapper.hasProp('checked', true)
2017
bool = wrapper.props().checked
21-
bool = wrapper.hasStyle('color', 'red')
2218
bool = wrapper.classes('foo')
2319

2420
bool = wrapper.is(normalOptions)
@@ -33,7 +29,6 @@ let o: string = wrapper.emitted('hello')[0]
3329
const emittedByOrder = wrapper.emittedByOrder()
3430
const name: string = emittedByOrder[0].name
3531

36-
wrapper.setComputed({computedProp: true})
3732
wrapper.setData({ foo: 'bar' })
3833
wrapper.setMethods({checked: true})
3934
wrapper.setProps({ checked: true })

Diff for: test/specs/components/TransitionStub.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ describeWithShallowAndMount('TransitionStub', mountingMethod => {
4343
transition: TransitionStub
4444
}
4545
})
46-
expect(wrapper.find('nav').visible()).to.equal(false)
46+
expect(wrapper.find('nav').isVisible()).to.equal(false)
4747
wrapper.find('button').trigger('click')
48-
expect(wrapper.find('nav').visible()).to.equal(true)
48+
expect(wrapper.find('nav').isVisible()).to.equal(true)
4949
wrapper.find('button').trigger('click')
50-
expect(wrapper.find('nav').visible()).to.equal(false)
50+
expect(wrapper.find('nav').isVisible()).to.equal(false)
5151
})
5252

5353
it('logs error when has multiple children', () => {

0 commit comments

Comments
 (0)