1
1
/* eslint-disable no-console */
2
2
3
3
import Vue from 'vue/dist/vue.common' ;
4
+ import { isShow , continuesCall , fakeBox } from '../utils' ;
4
5
import InfiniteLoading from '../../../src/components/InfiniteLoading.vue' ;
5
6
6
- /**
7
- * check display status for a specific element
8
- * @param {DOM } elm
9
- * @return {Boolean }
10
- */
11
- function isShow ( elm ) {
12
- return getComputedStyle ( elm ) . display !== 'none' ;
13
- }
14
-
15
- /**
16
- * continues call the specified number of times for a function
17
- * @param {Function } fn target function
18
- * @param {Number } times calls
19
- * @param {Function } cb [description]
20
- */
21
- function continuesCall ( fn , times , cb ) {
22
- if ( times ) {
23
- fn ( ) ;
24
- setTimeout ( ( ) => {
25
- continuesCall ( fn , times - 1 , cb ) ;
26
- } , 1 ) ;
27
- } else {
28
- cb ( ) ;
29
- }
30
- }
31
-
32
7
describe ( 'vue-infinite-loading:component' , ( ) => {
33
8
let vm ; // save Vue model
34
9
const basicConfig = {
@@ -315,20 +290,19 @@ describe('vue-infinite-loading:component', () => {
315
290
} ) ;
316
291
317
292
it ( 'should still works properly with the deprecated property `:on-infinite` but throw warning' , ( done ) => {
318
- const originalError = console . warn ;
319
293
let isThrowWarn ;
320
294
321
- console . warn = ( text ) => {
295
+ console . warn = fakeBox ( console . warn , ( text ) => {
322
296
if ( text . indexOf ( '@infinite' ) > - 1 ) {
323
297
isThrowWarn = true ;
324
298
}
325
- } ;
299
+ } ) ;
326
300
327
301
vm = new Vue ( Object . assign ( { } , basicConfig , {
328
302
methods : {
329
303
onInfinite : function onInfinite ( ) {
330
304
expect ( isThrowWarn ) . to . be . true ;
331
- console . warn = originalError ;
305
+ console . warn = fakeBox ( ) ;
332
306
done ( ) ;
333
307
} ,
334
308
} ,
@@ -431,14 +405,13 @@ describe('vue-infinite-loading:component', () => {
431
405
} ) ;
432
406
433
407
it ( 'should still works properly with the $refs.component.$emit but throw warning' , ( done ) => {
434
- const originalError = console . warn ;
435
408
let throwWarnTimes = 0 ;
436
409
437
- console . warn = ( text ) => {
410
+ console . warn = fakeBox ( console . warn , ( text ) => {
438
411
if ( text . indexOf ( '$state' ) > - 1 ) {
439
412
throwWarnTimes += 1 ;
440
413
}
441
- } ;
414
+ } ) ;
442
415
443
416
vm = new Vue ( Object . assign ( { } , basicConfig , {
444
417
methods : {
@@ -448,7 +421,7 @@ describe('vue-infinite-loading:component', () => {
448
421
} else {
449
422
this . $refs . infiniteLoading . $emit ( '$InfiniteLoading:complete' ) ;
450
423
expect ( throwWarnTimes ) . to . equal ( 2 ) ;
451
- console . warn = originalError ;
424
+ console . warn = fakeBox ( ) ;
452
425
done ( ) ;
453
426
}
454
427
} ,
@@ -490,14 +463,13 @@ describe('vue-infinite-loading:component', () => {
490
463
} ) ;
491
464
492
465
it ( 'should throw error when the component be in a infinite loop caused by a wrapper with unfixed height' , ( done ) => {
493
- const originalError = console . error ;
494
466
let isThrowError ;
495
467
496
- console . error = ( text ) => {
468
+ console . error = fakeBox ( console . error , ( text ) => {
497
469
if ( text . indexOf ( 'issues/55' ) > - 1 ) {
498
470
isThrowError = true ;
499
471
}
500
- } ;
472
+ } ) ;
501
473
502
474
vm = new Vue ( Object . assign ( { } , basicConfig , {
503
475
template : `
@@ -521,7 +493,7 @@ describe('vue-infinite-loading:component', () => {
521
493
} else {
522
494
$state . complete ( ) ;
523
495
expect ( isThrowError ) . to . be . true ;
524
- console . error = originalError ;
496
+ console . error = fakeBox ( ) ;
525
497
// wait for the loop check flag be marked as true
526
498
setTimeout ( ( ) => {
527
499
expect ( this . $refs . infiniteLoading . infiniteLoopChecked ) . to . be . true ;
0 commit comments