Skip to content

Commit 8d0e6b1

Browse files
committed
Add unit test for the keep-alive support feature
1 parent afb118a commit 8d0e6b1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/unit/specs/InfiniteLoading.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,50 @@ describe('InfiniteLoading.vue', () => {
213213

214214
vm.$mount('#app');
215215
});
216+
217+
it('should load data once when deactivated by keep-alive feature', (done) => {
218+
let callCount = 0;
219+
let app;
220+
221+
const InfiniteComponent = {
222+
data: initConf.data,
223+
template: initConf.template,
224+
components: initConf.components,
225+
methods: {
226+
onInfinite() {
227+
callCount++;
228+
if (callCount === 1) {
229+
this.$parent.currentView = null;
230+
Vue.nextTick(() => {
231+
this.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
232+
setTimeout(() => {
233+
expect(callCount).to.equal(1);
234+
app.$destroy(true);
235+
app.$el && app.$el.remove();
236+
done();
237+
}, 1000);
238+
});
239+
}
240+
},
241+
},
242+
};
243+
244+
app = new Vue({
245+
data() {
246+
return {
247+
currentView: 'InfiniteComponent',
248+
};
249+
},
250+
template: `
251+
<keep-alive>
252+
<component :is="currentView"></component>
253+
</keep-alive>
254+
`,
255+
components: {
256+
InfiniteComponent,
257+
},
258+
});
259+
260+
app.$mount('#app');
261+
});
216262
});

0 commit comments

Comments
 (0)