Răsfoiți Sursa

Switch: set checkbox checked property

wacky6.AriesMBP 8 ani în urmă
părinte
comite
84f8168783
2 a modificat fișierele cu 26 adăugiri și 0 ștergeri
  1. 1 0
      packages/switch/src/component.vue
  2. 25 0
      test/unit/specs/switch.spec.js

+ 1 - 0
packages/switch/src/component.vue

@@ -111,6 +111,7 @@
     },
     watch: {
       checked() {
+        this.$refs.input.checked = this.checked;
         if (this.onColor || this.offColor) {
           this.setBackgroundColor();
         }

+ 25 - 0
test/unit/specs/switch.spec.js

@@ -175,4 +175,29 @@ describe('Switch', () => {
       }, 10);
     }, 10);
   });
+
+  it('sets checkbox value', done => {
+    vm = createVue({
+      template: `
+        <div>
+          <el-switch v-model="value"></el-switch>
+        </div>
+      `,
+      data() {
+        return {
+          value: false
+        };
+      }
+    }, true);
+
+    vm.value = true;
+    setTimeout(() => {
+      expect(vm.$el.querySelector('input').checked).to.equal(true);
+      vm.value = false;
+      setTimeout(() => {
+        expect(vm.$el.querySelector('input').checked).to.equal(false);
+        done();
+      }, 10);
+    }, 10);
+  });
 });