Browse Source

feat: switch单元测试

zongyue3 4 years ago
parent
commit
81f7ef7e49
1 changed files with 42 additions and 0 deletions
  1. 42 0
      src/packages/__VUE/switch/__tests__/switch.spec.ts

+ 42 - 0
src/packages/__VUE/switch/__tests__/switch.spec.ts

@@ -0,0 +1,42 @@
+import { mount } from '@vue/test-utils';
+import Switch from '../index.vue';
+
+test('render ok', () => {
+  const wrapper = mount(Switch);
+
+  expect(wrapper.classes()).toContain('nut-switch-base');
+});
+
+test('emit click event', () => {
+  const wrapper = mount(Switch);
+
+  wrapper.trigger('click');
+  expect(wrapper.emitted('change')).toBeTruthy();
+});
+
+test('prop modelValue test', () => {
+  const wrapper = mount(Switch, {
+    props: {
+      modelValue: true
+    }
+  });
+  expect(wrapper.classes()).toContain('switch-open');
+});
+
+test('prop disable test', () => {
+  const wrapper = mount(Switch, {
+    props: {
+      disable: true
+    }
+  });
+  expect(wrapper.classes()).toContain('nut-switch-disable');
+});
+
+test('prop activeText test', () => {
+  const wrapper = mount(Switch, {
+    props: {
+      activeText: 'test text'
+    }
+  });
+  expect(wrapper.html()).toContain('test text');
+});