3
3
import Vue from 'vue'
4
4
import pretty from 'pretty'
5
5
import 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'
7
12
import config from './config'
8
13
import WrapperArray from './wrapper-array'
9
14
import ErrorWrapper from './error-wrapper'
10
- import { throwError , getCheckedEvent , isPhantomJS } from 'shared/util'
15
+ import { throwError , getCheckedEvent , isPhantomJS , warn } from 'shared/util'
11
16
import find from './find'
12
17
import createWrapper from './create-wrapper'
13
18
import { recursivelySetData } from './recursively-set-data'
@@ -117,6 +122,9 @@ export default class Wrapper implements BaseWrapper {
117
122
* Checks if wrapper contains provided selector.
118
123
*/
119
124
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
+ )
120
128
const selector = getSelector ( rawSelector , 'contains' )
121
129
const nodes = find ( this . rootNode , this . vm , selector )
122
130
return nodes . length > 0
@@ -163,6 +171,9 @@ export default class Wrapper implements BaseWrapper {
163
171
* Returns an Array containing custom events emitted by the Wrapper vm
164
172
*/
165
173
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
+ )
166
177
if ( ! this . _emittedByOrder && ! this . vm ) {
167
178
throwError (
168
179
`wrapper.emittedByOrder() can only be called on a Vue instance`
@@ -190,6 +201,9 @@ export default class Wrapper implements BaseWrapper {
190
201
* matches the provided selector.
191
202
*/
192
203
get ( rawSelector : Selector ) : Wrapper {
204
+ warn (
205
+ 'get is deprecated and will be removed in a future release. Use `find` or `findComponent` instead'
206
+ )
193
207
const found = this . find ( rawSelector )
194
208
if ( found instanceof ErrorWrapper ) {
195
209
throw new Error ( `Unable to find ${ rawSelector } within: ${ this . html ( ) } ` )
@@ -198,11 +212,16 @@ export default class Wrapper implements BaseWrapper {
198
212
}
199
213
200
214
/**
201
- * Finds first node in tree of the current wrapper that
215
+ * Finds first DOM node in tree of the current wrapper that
202
216
* matches the provided selector.
203
217
*/
204
218
find ( rawSelector : Selector ) : Wrapper | ErrorWrapper {
205
219
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
+ }
206
225
const node = find ( this . rootNode , this . vm , selector ) [ 0 ]
207
226
208
227
if ( ! node ) {
@@ -215,11 +234,63 @@ export default class Wrapper implements BaseWrapper {
215
234
}
216
235
217
236
/**
218
- * Finds node in tree of the current wrapper that matches
237
+ * Finds DOM elements in tree of the current wrapper that matches
219
238
* the provided selector.
220
239
*/
221
240
findAll ( rawSelector : Selector ) : WrapperArray {
222
241
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
+ }
223
294
const nodes = find ( this . rootNode , this . vm , selector )
224
295
const wrappers = nodes . map ( node => {
225
296
// Using CSS Selector, returns a VueWrapper instance if the root element
@@ -245,6 +316,9 @@ export default class Wrapper implements BaseWrapper {
245
316
* Checks if node matches selector
246
317
*/
247
318
is ( rawSelector : Selector ) : boolean {
319
+ warn (
320
+ `is is deprecated and will be removed in a future release. Use element.tagName instead`
321
+ )
248
322
const selector = getSelector ( rawSelector , 'is' )
249
323
250
324
if ( selector . type === REF_SELECTOR ) {
@@ -258,6 +332,10 @@ export default class Wrapper implements BaseWrapper {
258
332
* Checks if node is empty
259
333
*/
260
334
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
+ )
261
339
if ( ! this . vnode ) {
262
340
return this . element . innerHTML === ''
263
341
}
@@ -282,6 +360,8 @@ export default class Wrapper implements BaseWrapper {
282
360
* Checks if node is visible
283
361
*/
284
362
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` )
285
365
let element = this . element
286
366
while ( element ) {
287
367
if (
@@ -302,6 +382,7 @@ export default class Wrapper implements BaseWrapper {
302
382
* Checks if wrapper is a vue instance
303
383
*/
304
384
isVueInstance ( ) : boolean {
385
+ warn ( `isVueInstance is deprecated and will be removed in a future release` )
305
386
return ! ! this . vm
306
387
}
307
388
@@ -529,6 +610,7 @@ export default class Wrapper implements BaseWrapper {
529
610
* Sets vm methods
530
611
*/
531
612
setMethods ( methods : Object ) : void {
613
+ warn ( `setMethods is deprecated and will be removed in a future release` )
532
614
if ( ! this . isVueInstance ( ) ) {
533
615
throwError ( `wrapper.setMethods() can only be called on a Vue instance` )
534
616
}
0 commit comments