Browse Source

test(shortpassword,swiper,avatar): modify test (#1047)

Drjingfubo 3 years ago
parent
commit
023adb0f37

+ 4 - 2
src/packages/__VUE/avatar/__tests__/avatar.spec.ts

@@ -12,7 +12,7 @@ afterAll(() => {
   config.global.components = {};
 });
 
-test('size props', () => {
+test('size props', async () => {
   const wrapper = mount(Avatar, {
     props: {
       size: 'small'
@@ -20,12 +20,14 @@ test('size props', () => {
   });
   const avatar: any = wrapper.find('.nut-avatar');
   expect(avatar.classes()).toContain('avatar-small');
+  await wrapper.setProps({ size: 'large' });
+  expect(avatar.classes()).toContain('avatar-large');
 });
 
 test('shape props', () => {
   const wrapper = mount(Avatar, {
     props: {
-      size: 'square'
+      shape: 'square'
     }
   });
   const avatar: any = wrapper.find('.nut-avatar');

+ 12 - 7
src/packages/__VUE/shortpassword/__tests__/index.spec.ts

@@ -2,7 +2,7 @@ import { config, DOMWrapper, mount } from '@vue/test-utils';
 import ShortPassword from '../index.vue';
 import { nextTick } from 'vue';
 import NutIcon from '../../icon/index.vue';
-import NutPopup from '../../icon/index.vue';
+import NutPopup from '../../popup/index.vue';
 
 beforeAll(() => {
   config.global.components = {
@@ -18,8 +18,9 @@ afterAll(() => {
 test('should render shortpassword when visible is true', async () => {
   const wrapper = mount(ShortPassword, {
     props: {
-      visible: true,
-      modelValue: '123'
+      visible: false,
+      modelValue: '123',
+      isWrapTeleport: false
     }
   });
   const input: DOMWrapper<Element> = wrapper.find('.nut-input-real');
@@ -36,7 +37,8 @@ test('should render buttonShortpassword and error msg when noButton is false ',
       errorMsg: '错误信息',
       length: 4,
       modelValue: '123',
-      noButton: false
+      noButton: false,
+      isWrapTeleport: false
     }
   });
   const input = wrapper.find('.nut-input-real');
@@ -60,7 +62,8 @@ test('should change  value when prop changed', async () => {
   const wrapper = mount(ShortPassword, {
     props: {
       visible: true,
-      modelValue: '777'
+      modelValue: '777',
+      isWrapTeleport: false
     }
   });
   expect((wrapper.emitted('update:modelValue') as any)[0][0]).toEqual('777');
@@ -72,7 +75,8 @@ test('should format input value when input', async () => {
   const wrapper = mount(ShortPassword, {
     props: {
       visible: true,
-      modelValue: ''
+      modelValue: '',
+      isWrapTeleport: false
     }
   });
   const div: DOMWrapper<Element> = wrapper.find('.nut-shortpsd-fake');
@@ -95,7 +99,8 @@ test('should output input value when finish', async () => {
   const wrapper = mount(ShortPassword, {
     props: {
       visible: true,
-      modelValue: ''
+      modelValue: '',
+      isWrapTeleport: false
     }
   });
   const div: DOMWrapper<Element> = wrapper.find('.nut-shortpsd-fake');

+ 5 - 0
src/packages/__VUE/shortpassword/index.vue

@@ -11,6 +11,7 @@
       @click-close-icon="closeIcon"
       :close-on-click-overlay="closeOnClickOverlay"
       @click-overlay="close"
+      :isWrapTeleport="isWrapTeleport"
     >
       <view class="nut-shortpsd-title">{{ title }}</view>
       <view class="nut-shortpsd-subtitle">{{ desc }}</view>
@@ -87,6 +88,10 @@ export default create({
     length: {
       type: [String, Number], //4~6
       default: 6
+    },
+    isWrapTeleport: {
+      type: Boolean,
+      default: true
     }
   },
   emits: ['update:modelValue', 'update:visible', 'complete', 'change', 'ok', 'tips', 'close', 'cancel'],

+ 0 - 5
src/packages/__VUE/swiper/__tests__/index.spec.ts

@@ -76,7 +76,6 @@ test('should render initpage', async () => {
   });
 
   await nextTick();
-  await nextTick();
 
   const swiperItem = wrapper.findAll('.nut-swiper-inner')[0].element as HTMLElement;
 
@@ -114,7 +113,6 @@ test('should render direction', async () => {
   });
 
   await nextTick();
-  await nextTick();
 
   const swiperItem = wrapper.findAll('.nut-swiper-inner')[0].element as HTMLElement;
 
@@ -152,7 +150,6 @@ test('should render pagination', async () => {
   });
 
   await nextTick();
-  await nextTick();
 
   const swiperPagination = wrapper.find('.nut-swiper-pagination');
   expect(swiperPagination.exists()).toBe(true);
@@ -199,7 +196,6 @@ test('should render loop and auto-play', async () => {
   });
 
   await nextTick();
-  await nextTick();
 
   await sleep(200);
   const swiperItem = wrapper.findAll('.nut-swiper-inner')[0].element as HTMLElement;
@@ -261,7 +257,6 @@ test('should not allow to drag when loop is false', async () => {
   });
 
   await nextTick();
-  await nextTick();
 
   await sleep(2000);
   expect(wrapper.vm.page).toBe(3);

+ 0 - 1
src/sites/doc/components/demo-block/demoBlock.vue

@@ -100,7 +100,6 @@ export default defineConfig({
     onMounted(() => {
       const sourceValue = decompressText(onlineCode.value.dataset.value);
       codeType.value = onlineCode.value.dataset.type;
-
       const parameters = getParameters({
         files: {
           'package.json': {