Browse Source

fix: shortpassword 单元测试

guoxiaoxiao8 4 years ago
parent
commit
8883c5e12b

+ 1 - 0
jest.config.js

@@ -8,6 +8,7 @@ module.exports = {
   },
   // 匹配 __tests__ 目录下的 .js/.ts 文件 或其他目录下的 xx.test.js/ts xx.spec.js/ts
   testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(ts)$',
+  //testRegex: '__tests__.action.spec.ts',
   // 支持源代码中相同的 `@` -> `src` 别名
   moduleNameMapper: {
     '^@/(.*)$': '<rootDir>/src/$1'

+ 11 - 0
src/packages/__VUE/actionsheet/__tests__/action.spec.ts

@@ -0,0 +1,11 @@
+import Icon from '../../icon/index.vue';
+import ActionSheet from '../index.vue';
+
+import { mount } from '@vue/test-utils';
+test('base', () => {
+  const wrapper = mount(ActionSheet, {
+    props: {
+      visible: true
+    }
+  });
+});

+ 79 - 0
src/packages/__VUE/shortpassword/__tests__/shortpassword.spec.ts

@@ -0,0 +1,79 @@
+import { mount } from '@vue/test-utils';
+import ShortPassword from '../index.vue';
+import Icon from '../../icon/index.vue';
+
+test('base', () => {
+  const wrapper = mount(ShortPassword, {
+    props: {
+      visible: true,
+      value: 123
+    }
+  });
+  const input: any = wrapper.find('.nut-input-real');
+  expect(input.exists()).toBe(true);
+  expect(input.attributes('maxlength')).toBe('6');
+  expect(input.element.value).toBe('123');
+  //代码还没处理modelvalue值
+});
+test('base length and error', () => {
+  const wrapper = mount(ShortPassword, {
+    props: {
+      visible: true,
+      length: 4,
+      errorMsg: '错误信息',
+      noButton: false,
+      value: 'qwe'
+    }
+  });
+  const input = wrapper.find('.nut-input-real');
+  expect(input.exists()).toBe(true);
+  // expect(input.attributes("maxlength")).toBe("4");
+  const error = wrapper.find('.nut-shortpsd-error');
+  expect(error.exists()).toBe(true);
+  expect(error.text()).toBe('错误信息');
+  const cancle = wrapper.find('.nut-shortpsd-cancle');
+  expect(cancle.exists()).toBe(true);
+  const sure = wrapper.find('.nut-shortpsd-sure');
+  expect(sure.exists()).toBe(true);
+  cancle.trigger('click');
+  expect(wrapper.emitted('cancel')).toBeTruthy();
+  sure.trigger('click');
+  expect((wrapper.emitted('ok') as any)[0][0]).toBe('qwe');
+});
+
+test('event callback', async () => {
+  const wrapper = mount(ShortPassword, {
+    props: {
+      visible: true
+    }
+  });
+  const input: any = wrapper.find('.nut-input-real');
+  await input.trigger('click');
+  await input.trigger('input');
+  await wrapper.trigger('keydown', {
+    key: '123'
+  });
+  setTimeout(() => {
+    expect(wrapper.emitted('change') as any).toBe('123');
+  }, 400);
+
+  //代码还没处理modelvalue值
+});
+test('event callback', async () => {
+  const wrapper = mount(ShortPassword, {
+    props: {
+      visible: true
+    }
+  });
+  const input: any = wrapper.find('.nut-input-real');
+  await input.trigger('click');
+  await input.trigger('input');
+  await wrapper.trigger('keydown', {
+    key: '123456'
+  });
+  setTimeout(() => {
+    expect(wrapper.emitted('complete') as any).toBe('123456');
+  }, 400);
+
+  //代码还没处理modelvalue值
+});

+ 0 - 10
src/packages/__VUE/textarea/__tests__/textarea.spec.ts

@@ -1,10 +0,0 @@
-import { mount } from '@vue/test-utils';
-
-import TextArea from '../index.vue';
-
-test('Textarea base', () => {
-  //const wrapper = mount(TextArea, { props: { modelValue: 3 } });
-  // const input = wrapper.find('input');
-  // expect(input.exists()).toBe(true);
-  // expect(input.element.value).toBe("3");
-});