添加单元测试 (#12)

* 添加单元测试
This commit is contained in:
张敏 2017-04-25 19:57:17 +08:00 committed by GitHub
parent 1de88fb939
commit dd5e2eefa9
4 changed files with 38 additions and 4 deletions

View File

@ -11,12 +11,13 @@ var ISNTALL_COMPONENT_TEMPLATE = ' Vue.component({{name}}.name, {{name}});';
var MAIN_TEMPLATE = `{{include}}
const install = function(Vue) {
/* istanbul ignore if */
if (install.installed) return;
{{install}}
};
// auto install
/* istanbul ignore if */
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue);
}

View File

@ -37,6 +37,7 @@ import SwipeItem from '../packages/swipe-item/index.js';
import DatetimePicker from '../packages/datetime-picker/index.js';
const install = function(Vue) {
/* istanbul ignore if */
if (install.installed) return;
Vue.component(Button.name, Button);
@ -73,7 +74,7 @@ const install = function(Vue) {
Vue.component(DatetimePicker.name, DatetimePicker);
};
// auto install
/* istanbul ignore if */
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue);
}

View File

@ -47,7 +47,7 @@ const webpackConfig = {
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules|vue-router\/|vue-loader\/|vue-hot-reload-api\/|docs|test|src\/index/,
exclude: /node_modules|vue-router\/|vue-loader\/|vue-hot-reload-api\/|docs|test|src\/index|packages\/swipe/,
use: ['isparta-loader']
},
{
@ -76,7 +76,7 @@ const webpackConfig = {
}]
},
{
test: /test\/unit\/components\/.*\.vue$/,
test: /test\/unit\/components\/.*\.vue$|packages\/swipe\/.*\.vue$/,
use: [{
loader: 'vue-loader',
options: {
@ -92,6 +92,7 @@ const webpackConfig = {
},
{
test: /packages\/.*\.vue$/,
exclude: /packages\/swipe/,
use: [{
loader: 'vue-loader',
options: {

View File

@ -0,0 +1,31 @@
import { hasClass, addClass, removeClass } from 'src/utils/dom';
describe('Utils Dom', () => {
let wrapper;
beforeEach(() => {
wrapper = document.createElement('div');
wrapper.classList.add('test-class');
document.body.appendChild(wrapper);
});
afterEach(() => {
document.body.removeChild(wrapper);
});
it('hasClass', () => {
expect(hasClass(wrapper, 'test-class')).to.be.true;
expect(hasClass()).to.be.false;
});
it('addClass and removeClass', () => {
expect(hasClass(wrapper, 'test-class')).to.be.true;
addClass(wrapper, ' other-class');
expect(hasClass(wrapper, 'other-class')).to.be.true;
expect(addClass()).to.equal(undefined);
removeClass(wrapper, ' other-class');
expect(hasClass(wrapper, 'other-class')).to.be.false;
expect(removeClass()).to.equal(undefined);
});
});