浏览代码

test: add switch (#479)

* feat: switch单元测试

* test: cell单元测试
JackieScorpio 4 年之前
父节点
当前提交
0fee94822b
共有 2 个文件被更改,包括 84 次插入0 次删除
  1. 42 0
      src/packages/__VUE/cell/__tests__/cell.spec.ts
  2. 42 0
      src/packages/__VUE/switch/__tests__/switch.spec.ts

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

@@ -0,0 +1,42 @@
+import { mount } from '@vue/test-utils';
+import Cell from '../index.vue';
+
+test('prop title desc', () => {
+  const wrapper = mount(Cell, {
+    props: {
+      title: '标题1',
+      desc: '描述1'
+    }
+  });
+
+  expect(wrapper.html()).toContain('标题1');
+  expect(wrapper.html()).toContain('描述1');
+});
+
+test('prop title subtitle', () => {
+  const wrapper = mount(Cell, {
+    props: {
+      title: '标题1',
+      subTitle: '副标题1'
+    }
+  });
+
+  expect(wrapper.html()).toContain('标题1');
+  expect(wrapper.html()).toContain('副标题1');
+});
+
+test('emit click event', () => {
+  const wrapper = mount(Cell);
+
+  wrapper.trigger('click');
+  expect(wrapper.emitted('click')!.length).toEqual(1);
+});
+
+test('slot test', () => {
+  const wrapper = mount(Cell, {
+    slots: {
+      default: '自定义内容'
+    }
+  });
+  expect(wrapper.html()).toContain('自定义内容');
+});

+ 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');
+});