Merge pull request #489 from QingWei-Li/test/util/popper

VuePopper: add test
This commit is contained in:
baiyaaaaa 2016-10-18 18:07:13 +08:00 committed by GitHub
commit 7175ad272d
2 changed files with 58 additions and 1 deletions

View File

@ -21,7 +21,7 @@
"clean": "rimraf lib && rimraf packages/*/lib",
"lint": "eslint src/**/* test/**/* packages/**/*.{js,vue} build/**/* --quiet",
"test:watch": "karma start test/unit/karma.conf.js",
"test": "karma start test/unit/karma.conf.js --single-run"
"test": "npm run lint && karma start test/unit/karma.conf.js --single-run"
},
"repository": {
"type": "git",

View File

@ -0,0 +1,57 @@
import VuePopper from 'element-ui/src/utils/vue-popper';
import { createTest } from '../util';
const Popper = Object.assign({}, VuePopper, {
render(h) {
return h('div');
},
created() {
this.popperElm = document.createElement('div');
this.referenceElm = document.createElement('div');
}
});
describe('Utils:VuePopper', () => {
it('createPopper', () => {
const vm = createTest(Popper, { placement: 'top' });
vm.createPopper();
expect(vm.popperJS._popper.getAttribute('x-placement')).to.equal('top');
});
it('doDestroy', () => {
const vm = createTest(Popper, { placement: 'top' });
vm.createPopper();
expect(vm.popperJS._popper.getAttribute('x-placement')).to.equal('top');
vm.doDestroy();
expect(vm.popperJS).to.not.exist;
});
it('placement', () => {
const vm = createTest(Popper, { placement: 'bottom-start' });
const vm2 = createTest(Popper, { placement: 'bottom-abc' });
vm.createPopper();
vm2.createPopper();
expect(vm.popperJS._popper.getAttribute('x-placement')).to.equal('bottom-start');
expect(vm2.popperJS).to.not.exist;
});
it('display arrow', () => {
const vm = createTest(Popper, {
visibleArrow: true
});
vm.createPopper();
expect(vm.popperJS._popper.querySelector('div[x-arrow]')).to.exist;
});
it('destroy', () => {
const vm = createTest(Popper, true);
vm.createPopper();
expect(document.body.contains(vm.popperElm)).to.true;
vm.$destroy();
expect(document.body.contains(vm.popperElm)).to.false;
});
});