Skip to content

Commit e4d9511

Browse files
committed
Add unit test for the $refs.x.$emit use warning
1 parent 6707f8c commit e4d9511

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/unit/specs/InfiniteLoading.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,32 @@ describe('vue-infinite-loading', () => {
405405

406406
vm.$mount('#app');
407407
});
408+
409+
it('should still works properly with the $refs.component.$emit but through warning', (done) => {
410+
const originalError = console.warn;
411+
let throughWarnTimes = 0;
412+
413+
console.warn = (text) => {
414+
if (text.indexOf('$state') > -1) {
415+
throughWarnTimes += 1;
416+
}
417+
};
418+
419+
vm = new Vue(Object.assign({}, basicConfig, {
420+
methods: {
421+
infiniteHandler: function infiniteHandler() {
422+
if (!throughWarnTimes) {
423+
this.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
424+
} else {
425+
this.$refs.infiniteLoading.$emit('$InfiniteLoading:complete');
426+
expect(throughWarnTimes).to.equal(2);
427+
console.warn = originalError;
428+
done();
429+
}
430+
},
431+
},
432+
}));
433+
434+
vm.$mount('#app');
435+
});
408436
});

0 commit comments

Comments
 (0)