添加单元测试 (#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

@@ -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);
});
});