33import Vue from 'vue'
44import pretty from 'pretty'
55import getSelector from './get-selector'
6- import { REF_SELECTOR , FUNCTIONAL_OPTIONS , VUE_VERSION } from 'shared/consts'
6+ import {
7+ REF_SELECTOR ,
8+ FUNCTIONAL_OPTIONS ,
9+ VUE_VERSION ,
10+ DOM_SELECTOR
11+ } from 'shared/consts'
712import config from './config'
813import WrapperArray from './wrapper-array'
914import ErrorWrapper from './error-wrapper'
10- import { throwError , getCheckedEvent , isPhantomJS } from 'shared/util'
15+ import { throwError , getCheckedEvent , isPhantomJS , warn } from 'shared/util'
1116import find from './find'
1217import createWrapper from './create-wrapper'
1318import { recursivelySetData } from './recursively-set-data'
@@ -117,6 +122,9 @@ export default class Wrapper implements BaseWrapper {
117122 * Checks if wrapper contains provided selector.
118123 */
119124 contains ( rawSelector : Selector ) : boolean {
125+ warn (
126+ 'contains is deprecated and will be removed in a future release. Use `wrapper.find`, `wrapper.findComponent` or `wrapper.get` instead'
127+ )
120128 const selector = getSelector ( rawSelector , 'contains' )
121129 const nodes = find ( this . rootNode , this . vm , selector )
122130 return nodes . length > 0
@@ -163,6 +171,9 @@ export default class Wrapper implements BaseWrapper {
163171 * Returns an Array containing custom events emitted by the Wrapper vm
164172 */
165173 emittedByOrder ( ) : Array < { name : string , args : Array < any > } > {
174+ warn (
175+ 'emittedByOrder is deprecated and will be removed in a future release. Use `wrapper.emitted` instead'
176+ )
166177 if ( ! this . _emittedByOrder && ! this . vm ) {
167178 throwError (
168179 `wrapper.emittedByOrder() can only be called on a Vue instance`
@@ -190,6 +201,9 @@ export default class Wrapper implements BaseWrapper {
190201 * matches the provided selector.
191202 */
192203 get ( rawSelector : Selector ) : Wrapper {
204+ warn (
205+ 'get is deprecated and will be removed in a future release. Use `find` or `findComponent` instead'
206+ )
193207 const found = this . find ( rawSelector )
194208 if ( found instanceof ErrorWrapper ) {
195209 throw new Error ( `Unable to find ${ rawSelector } within: ${ this . html ( ) } ` )
@@ -198,11 +212,16 @@ export default class Wrapper implements BaseWrapper {
198212 }
199213
200214 /**
201- * Finds first node in tree of the current wrapper that
215+ * Finds first DOM node in tree of the current wrapper that
202216 * matches the provided selector.
203217 */
204218 find ( rawSelector : Selector ) : Wrapper | ErrorWrapper {
205219 const selector = getSelector ( rawSelector , 'find' )
220+ if ( selector . type !== DOM_SELECTOR ) {
221+ warn (
222+ 'finding components with `find` is deprecated and will be removed in a future release. Use `findComponent` instead'
223+ )
224+ }
206225 const node = find ( this . rootNode , this . vm , selector ) [ 0 ]
207226
208227 if ( ! node ) {
@@ -215,11 +234,63 @@ export default class Wrapper implements BaseWrapper {
215234 }
216235
217236 /**
218- * Finds node in tree of the current wrapper that matches
237+ * Finds DOM elements in tree of the current wrapper that matches
219238 * the provided selector.
220239 */
221240 findAll ( rawSelector : Selector ) : WrapperArray {
222241 const selector = getSelector ( rawSelector , 'findAll' )
242+ if ( selector . type !== DOM_SELECTOR ) {
243+ warn (
244+ 'finding components with `findAll` is deprecated and will be removed in a future release. Use `findAllComponents` instead'
245+ )
246+ }
247+ const nodes = find ( this . rootNode , this . vm , selector )
248+ const wrappers = nodes . map ( node => {
249+ // Using CSS Selector, returns a VueWrapper instance if the root element
250+ // binds a Vue instance.
251+ const wrapper = createWrapper ( node , this . options )
252+ wrapper . selector = rawSelector
253+ return wrapper
254+ } )
255+
256+ const wrapperArray = new WrapperArray ( wrappers )
257+ wrapperArray . selector = rawSelector
258+ return wrapperArray
259+ }
260+
261+ /**
262+ * Finds first component in tree of the current wrapper that
263+ * matches the provided selector.
264+ */
265+ findComponent ( rawSelector : Selector ) : Wrapper | ErrorWrapper {
266+ const selector = getSelector ( rawSelector , 'findComponent' )
267+ if ( selector . type === DOM_SELECTOR ) {
268+ throwError (
269+ 'findComponent requires a Vue constructor or valid find object. If you are searching for DOM nodes, use `find` instead'
270+ )
271+ }
272+ const node = find ( this . rootNode , this . vm , selector ) [ 0 ]
273+
274+ if ( ! node ) {
275+ return new ErrorWrapper ( rawSelector )
276+ }
277+
278+ const wrapper = createWrapper ( node , this . options )
279+ wrapper . selector = rawSelector
280+ return wrapper
281+ }
282+
283+ /**
284+ * Finds components in tree of the current wrapper that matches
285+ * the provided selector.
286+ */
287+ findAllComponents ( rawSelector : Selector ) : WrapperArray {
288+ const selector = getSelector ( rawSelector , 'findAll' )
289+ if ( selector . type === DOM_SELECTOR ) {
290+ throwError (
291+ 'findAllComponent requires a Vue constructor or valid find object. If you are searching for DOM nodes, use `find` instead'
292+ )
293+ }
223294 const nodes = find ( this . rootNode , this . vm , selector )
224295 const wrappers = nodes . map ( node => {
225296 // Using CSS Selector, returns a VueWrapper instance if the root element
@@ -245,6 +316,9 @@ export default class Wrapper implements BaseWrapper {
245316 * Checks if node matches selector
246317 */
247318 is ( rawSelector : Selector ) : boolean {
319+ warn (
320+ `is is deprecated and will be removed in a future release. Use element.tagName instead`
321+ )
248322 const selector = getSelector ( rawSelector , 'is' )
249323
250324 if ( selector . type === REF_SELECTOR ) {
@@ -258,6 +332,10 @@ export default class Wrapper implements BaseWrapper {
258332 * Checks if node is empty
259333 */
260334 isEmpty ( ) : boolean {
335+ warn (
336+ `isEmpty is deprecated and will be removed in a future release. ` +
337+ `Consider a custom matcher such as those provided in jest-dom: https://github.com/testing-library/jest-dom#tobeempty`
338+ )
261339 if ( ! this . vnode ) {
262340 return this . element . innerHTML === ''
263341 }
@@ -282,6 +360,8 @@ export default class Wrapper implements BaseWrapper {
282360 * Checks if node is visible
283361 */
284362 isVisible ( ) : boolean {
363+ warn ( `isEmpty is deprecated and will be removed in a future release.
364+ Consider a custom matcher such as those provided in jest-dom: https://github.com/testing-library/jest-dom#tobevisible` )
285365 let element = this . element
286366 while ( element ) {
287367 if (
@@ -302,6 +382,7 @@ export default class Wrapper implements BaseWrapper {
302382 * Checks if wrapper is a vue instance
303383 */
304384 isVueInstance ( ) : boolean {
385+ warn ( `isVueInstance is deprecated and will be removed in a future release` )
305386 return ! ! this . vm
306387 }
307388
@@ -529,6 +610,7 @@ export default class Wrapper implements BaseWrapper {
529610 * Sets vm methods
530611 */
531612 setMethods ( methods : Object ) : void {
613+ warn ( `setMethods is deprecated and will be removed in a future release` )
532614 if ( ! this . isVueInstance ( ) ) {
533615 throwError ( `wrapper.setMethods() can only be called on a Vue instance` )
534616 }
0 commit comments