Explorar el Código

Message/Notification: improve test

Leopoldthecoder hace 8 años
padre
commit
a4175a74e2
Se han modificado 2 ficheros con 48 adiciones y 65 borrados
  1. 21 32
      test/unit/specs/message.spec.js
  2. 27 33
      test/unit/specs/notification.spec.js

+ 21 - 32
test/unit/specs/message.spec.js

@@ -1,17 +1,26 @@
-import { createVue, triggerEvent } from '../util';
+import { triggerEvent } from '../util';
+import Message from 'packages/message';
 
 describe('Message', () => {
+  afterEach(() => {
+    const el = document.querySelector('.el-message');
+    if (!el) return;
+    if (el.parentNode) {
+      el.parentNode.removeChild(el);
+    }
+    if (el.__vue__) {
+      el.__vue__.$destroy();
+    }
+  });
+
   it('automatically close', done => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$message({
+    Message({
       message: '灰风',
       duration: 500
     });
+    const message = document.querySelector('.el-message__group').childNodes[0];
     expect(document.querySelector('.el-message')).to.exist;
+    expect(message.textContent).to.equal('灰风');
     setTimeout(() => {
       expect(document.querySelector('.el-message')).to.not.exist;
       done();
@@ -19,12 +28,7 @@ describe('Message', () => {
   });
 
   it('manually close', done => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$message({
+    Message({
       message: '夏天',
       showClose: true
     });
@@ -38,32 +42,17 @@ describe('Message', () => {
   });
 
   it('create', () => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$message('娜梅莉亚');
+    Message('娜梅莉亚');
     expect(document.querySelector('.el-message')).to.exist;
   });
 
   it('invoke with type', () => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$message.success('毛毛狗');
-    expect(document.querySelector('.el-message')).to.exist;
+    Message.success('毛毛狗');
+    expect(document.querySelector('.el-message').__vue__.type).to.equal('success');
   });
 
   it('reset timer', done => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$message({
+    Message({
       message: '白灵',
       duration: 1000
     });

+ 27 - 33
test/unit/specs/notification.spec.js

@@ -1,13 +1,20 @@
-import { createVue, triggerEvent } from '../util';
+import { triggerEvent } from '../util';
+import Notification from 'packages/notification';
 
 describe('Notification', () => {
+  afterEach(() => {
+    const el = document.querySelector('.el-notification');
+    if (!el) return;
+    if (el.parentNode) {
+      el.parentNode.removeChild(el);
+    }
+    if (el.__vue__) {
+      el.__vue__.$destroy();
+    }
+  });
+
   it('automatically close', done => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$notify({
+    Notification({
       message: '玻璃蜡烛',
       duration: 500
     });
@@ -19,12 +26,7 @@ describe('Notification', () => {
   });
 
   it('manually close', done => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$notify({
+    Notification({
       message: '苍白母马'
     });
     setTimeout(() => {
@@ -37,34 +39,26 @@ describe('Notification', () => {
   });
 
   it('create', () => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$notify({
-      message: '狮鹫'
+    Notification({
+      title: '狮子',
+      message: '狮鹫',
+      duration: 0
     });
+    const group = document.querySelector('.el-notification__group');
+    const title = group.querySelector('span');
+    const message = group.querySelector('p');
     expect(document.querySelector('.el-notification')).to.exist;
+    expect(title.textContent).to.equal('狮子');
+    expect(message.textContent).to.equal('狮鹫');
   });
 
   it('invoke with type', () => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$notify.success('太阳之子');
-    expect(document.querySelector('.el-notification')).to.exist;
+    Notification.success('太阳之子');
+    expect(document.querySelector('.el-notification').__vue__.type).to.equal('success');
   });
 
   it('reset timer', done => {
-    const vm = createVue({
-      template: `
-      <div></div>
-    `
-    }, true);
-    vm.$notify({
+    Notification({
       message: '芳香总管',
       duration: 1000
     });