From dd5e2eefa998ae7bf2b00cdbb7d73f2cf9d53c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=95=8F?= Date: Tue, 25 Apr 2017 19:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20(#12)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加单元测试 --- build/bin/build-entry.js | 3 ++- src/index.js | 3 ++- test/unit/get-webpack-conf.js | 5 +++-- test/unit/specs/utils.dom.spec.js | 31 +++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 test/unit/specs/utils.dom.spec.js diff --git a/build/bin/build-entry.js b/build/bin/build-entry.js index b58e200be..b70e79e86 100644 --- a/build/bin/build-entry.js +++ b/build/bin/build-entry.js @@ -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); } diff --git a/src/index.js b/src/index.js index 0a41e427e..b14d581ca 100644 --- a/src/index.js +++ b/src/index.js @@ -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); } diff --git a/test/unit/get-webpack-conf.js b/test/unit/get-webpack-conf.js index a22da8e27..d1f22f309 100644 --- a/test/unit/get-webpack-conf.js +++ b/test/unit/get-webpack-conf.js @@ -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: { diff --git a/test/unit/specs/utils.dom.spec.js b/test/unit/specs/utils.dom.spec.js new file mode 100644 index 000000000..fd8258501 --- /dev/null +++ b/test/unit/specs/utils.dom.spec.js @@ -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); + }); +});