Skip to content

Commit 63e382c

Browse files
committed
Add unit test for no more data and no results tips feature
1 parent 4deb119 commit 63e382c

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

test/unit/specs/InfiniteLoading.spec.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import Vue from 'vue';
22
import InfiniteLoading from '../../../src/components/InfiniteLoading';
33

4+
function isShow(elm) {
5+
const styles = getComputedStyle(elm);
6+
7+
return styles.getPropertyValue('display') !== 'none';
8+
}
9+
410
describe('InfiniteLoading.vue', () => {
511
let vm;
612

713
// create new Vue instance for every test case
814
beforeEach(() => {
9-
if (vm) {
10-
vm.$destroy();
11-
}
12-
1315
vm = new Vue({
1416
data: {
1517
list: [],
@@ -35,6 +37,10 @@ describe('InfiniteLoading.vue', () => {
3537
});
3638
});
3739

40+
afterEach(() => {
41+
vm.$destroy();
42+
});
43+
3844
it('should render correct template', () => {
3945
vm.isDivScroll = false;
4046
vm.distance = undefined;
@@ -47,18 +53,12 @@ describe('InfiniteLoading.vue', () => {
4753
it('should appear a loading animation', (done) => {
4854
vm.onInfinite = function test() {
4955
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;
5457

5558
this.$broadcast('$InfiniteLoading:loaded');
5659

5760
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;
6262
done();
6363
});
6464
});
@@ -101,4 +101,28 @@ describe('InfiniteLoading.vue', () => {
101101

102102
vm.$mount().$appendTo('body');
103103
});
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+
});
104128
});

0 commit comments

Comments
 (0)