1
1
import Vue from 'vue' ;
2
2
import InfiniteLoading from '../../../src/components/InfiniteLoading' ;
3
3
4
+ function isShow ( elm ) {
5
+ const styles = getComputedStyle ( elm ) ;
6
+
7
+ return styles . getPropertyValue ( 'display' ) !== 'none' ;
8
+ }
9
+
4
10
describe ( 'InfiniteLoading.vue' , ( ) => {
5
11
let vm ;
6
12
7
13
// create new Vue instance for every test case
8
14
beforeEach ( ( ) => {
9
- if ( vm ) {
10
- vm . $destroy ( ) ;
11
- }
12
-
13
15
vm = new Vue ( {
14
16
data : {
15
17
list : [ ] ,
@@ -35,6 +37,10 @@ describe('InfiniteLoading.vue', () => {
35
37
} ) ;
36
38
} ) ;
37
39
40
+ afterEach ( ( ) => {
41
+ vm . $destroy ( ) ;
42
+ } ) ;
43
+
38
44
it ( 'should render correct template' , ( ) => {
39
45
vm . isDivScroll = false ;
40
46
vm . distance = undefined ;
@@ -47,18 +53,12 @@ describe('InfiniteLoading.vue', () => {
47
53
it ( 'should appear a loading animation' , ( done ) => {
48
54
vm . onInfinite = function test ( ) {
49
55
Vue . nextTick ( ( ) => {
50
- expect ( vm . $el . querySelector ( '.icon-loading' )
51
- . getAttribute ( 'style' )
52
- . indexOf ( 'display: none' ) === - 1 )
53
- . to . be . true ;
56
+ expect ( isShow ( vm . $el . querySelector ( '.icon-loading' ) ) ) . to . be . true ;
54
57
55
58
this . $broadcast ( '$InfiniteLoading:loaded' ) ;
56
59
57
60
Vue . nextTick ( ( ) => {
58
- expect ( vm . $el . querySelector ( '.icon-loading' )
59
- . getAttribute ( 'style' )
60
- . indexOf ( 'display: none' ) >= - 1 )
61
- . to . be . true ;
61
+ expect ( isShow ( vm . $el . querySelector ( '.icon-loading' ) ) ) . to . be . false ;
62
62
done ( ) ;
63
63
} ) ;
64
64
} ) ;
@@ -101,4 +101,28 @@ describe('InfiniteLoading.vue', () => {
101
101
102
102
vm . $mount ( ) . $appendTo ( 'body' ) ;
103
103
} ) ;
104
+
105
+ it ( 'should display no results tips' , ( done ) => {
106
+ vm . onInfinite = function test ( ) {
107
+ this . $broadcast ( '$InfiniteLoading:noResults' ) ;
108
+ Vue . nextTick ( ( ) => {
109
+ expect ( isShow ( vm . $el . querySelectorAll ( '.infinite-status-tips' ) [ 0 ] ) ) . to . be . true ;
110
+ done ( ) ;
111
+ } ) ;
112
+ } . bind ( vm ) ;
113
+
114
+ vm . $mount ( ) . $appendTo ( 'body' ) ;
115
+ } ) ;
116
+
117
+ it ( 'should display no more data tips' , ( done ) => {
118
+ vm . onInfinite = function test ( ) {
119
+ this . $broadcast ( '$InfiniteLoading:noMore' ) ;
120
+ Vue . nextTick ( ( ) => {
121
+ expect ( isShow ( vm . $el . querySelectorAll ( '.infinite-status-tips' ) [ 1 ] ) ) . to . be . true ;
122
+ done ( ) ;
123
+ } ) ;
124
+ } . bind ( vm ) ;
125
+
126
+ vm . $mount ( ) . $appendTo ( 'body' ) ;
127
+ } ) ;
104
128
} ) ;
0 commit comments