Skip to content

Commit c4c74aa

Browse files
committed
test: add unit tests for the plugin install feature
1 parent aa98736 commit c4c74aa

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

test/unit/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// mock passive event listener support and upsupport
1+
import Vue from 'vue/dist/vue.common';
2+
3+
// mock passive event listener support and not support
24
(() => {
35
const originAddListener = window.addEventListener;
46
let flag;
@@ -12,8 +14,14 @@
1214
};
1315
})();
1416

17+
// disable Vue production tip
18+
Vue.config.productionTip = false;
19+
20+
// setup global Vue manually
21+
window.Vue = Vue;
22+
1523
const testsContext = require.context('./specs', true, /\.spec$/);
1624
testsContext.keys().forEach(testsContext);
1725

18-
const srcContext = require.context('../../src', true, /^\/(?!index(\.js)?$)/);
26+
const srcContext = require.context('../../src', true, /\.js$/);
1927
srcContext.keys().forEach(srcContext);

test/unit/specs/InfiniteLoading.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import Vue from 'vue/dist/vue.common';
44
import InfiniteLoading from '../../../src/components/InfiniteLoading.vue';
55

6-
Vue.config.productionTip = false;
7-
86
/**
97
* check display status for a specific element
108
* @param {DOM} elm
@@ -31,7 +29,7 @@ function continuesCall(fn, times, cb) {
3129
}
3230
}
3331

34-
describe('vue-infinite-loading', () => {
32+
describe('vue-infinite-loading:component', () => {
3533
let vm; // save Vue model
3634
const basicConfig = {
3735
data: {
@@ -275,7 +273,7 @@ describe('vue-infinite-loading', () => {
275273
list: [],
276274
isDivScroll: true,
277275
direction: 'top',
278-
spinner: 'unknown',
276+
spinner: 'default',
279277
};
280278
},
281279
methods: {
@@ -473,7 +471,7 @@ describe('vue-infinite-loading', () => {
473471
:direction="direction"
474472
@infinite="infiniteHandler"
475473
ref="infiniteLoading"
476-
force-use-infinite-wrapper
474+
force-use-infinite-wrapper="true"
477475
>
478476
</infinite-loading>
479477
</div>

test/unit/specs/index.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Vue from 'vue/dist/vue.common';
2+
import InfiniteLoading from '../../../src';
3+
import config from '../../../src/config';
4+
5+
describe('vue-infinite-loading:index', () => {
6+
const options = {
7+
props: { distance: 200 },
8+
};
9+
10+
function getRunningModeFromVue() {
11+
return Vue.config.productionTip ? 'development' : 'production';
12+
}
13+
14+
afterEach(() => {
15+
// clear component
16+
delete Vue.options.components['infinite-loading'];
17+
});
18+
19+
it('should register component automatically if there has global Vue', () => {
20+
expect(Vue.options.components['infinite-loading']).to.not.be.undefined;
21+
});
22+
23+
it('should register component, sync app running mode from Vue, and override config when using the plugin install API', () => {
24+
// assert before install
25+
expect(config.mode).to.equal(getRunningModeFromVue());
26+
expect(config.props.distance).to.not.equal(options.props.distance);
27+
28+
// change running mode for Vue
29+
Vue.config.productionTip = true;
30+
31+
// install plugin
32+
Vue.use(InfiniteLoading, options);
33+
34+
// assert after install
35+
expect(config.props.distance).to.equal(options.props.distance);
36+
expect(config.mode).to.equal(getRunningModeFromVue());
37+
});
38+
});

0 commit comments

Comments
 (0)