Selaa lähdekoodia

Tooltip: add test (#487)

cinwell.li 8 vuotta sitten
vanhempi
commit
815bdd47d0
3 muutettua tiedostoa jossa 52 lisäystä ja 2 poistoa
  1. 2 1
      build/bin/build-entry.js
  2. 2 1
      src/index.js
  3. 48 0
      test/unit/specs/tooltip.spec.js

+ 2 - 1
build/bin/build-entry.js

@@ -10,6 +10,7 @@ var INSTALL_COMPONENT_TEMPLATE = '  Vue.component({{name}}.name, {{name}});';
 var MAIN_TEMPLATE = `{{include}}
 
 const install = function(Vue) {
+  /* istanbul ignore if */
   if (install.installed) return;
 
 {{install}}
@@ -24,7 +25,7 @@ const install = function(Vue) {
   Vue.prototype.$message = Message;
 };
 
-// auto install
+/* istanbul ignore if */
 if (typeof window !== 'undefined' && window.Vue) {
   install(window.Vue);
 };

+ 2 - 1
src/index.js

@@ -55,6 +55,7 @@ import Steps from '../packages/steps/index.js';
 import Step from '../packages/step/index.js';
 
 const install = function(Vue) {
+  /* istanbul ignore next */
   if (install.installed) return;
 
   Vue.component(Pagination.name, Pagination);
@@ -119,7 +120,7 @@ const install = function(Vue) {
   Vue.prototype.$message = Message;
 };
 
-// auto install
+/* istanbul ignore next */
 if (typeof window !== 'undefined' && window.Vue) {
   install(window.Vue);
 };

+ 48 - 0
test/unit/specs/tooltip.spec.js

@@ -0,0 +1,48 @@
+import { createVue } from '../util';
+
+describe('Tooltip', () => {
+  it('create', () => {
+    const vm = createVue(`
+      <el-tooltip content="提示文字">
+        <button>click</button>
+      </el-tooltip>`);
+
+    expect(vm.$el.querySelector('.el-tooltip__popper')).to.exist;
+    expect(vm.$el.querySelector('.el-tooltip__popper').textContent).to.equal('提示文字');
+  });
+
+  it('hover', done => {
+    const vm = createVue(`
+      <el-tooltip ref="tooltip" content="提示文字">
+        <button>click</button>
+      </el-tooltip>
+    `, true);
+    const tooltip = vm.$refs.tooltip;
+
+    // trigger mouseenter
+    tooltip.handleShowPopper();
+
+    expect(tooltip.popperElm).to.not.exist;
+    setTimeout(_ => {
+      expect(tooltip.popperElm).to.exist;
+      expect(tooltip.popperElm.style.display).to.not.equal('none');
+
+      // trigger mouseleave
+      tooltip.handleClosePopper();
+
+      setTimeout(_ => {
+        expect(tooltip.popperElm.style.display).to.equal('none');
+        done();
+      }, 500);
+    }, 150);
+  });
+
+  it('light mode', () => {
+    const vm = createVue(`
+      <el-tooltip content="abc" effect="light">
+        <button>abc</button>
+      </el-tooltip>
+    `);
+    expect(vm.$el.querySelector('.is-light')).to.exist;
+  });
+});