From 83755077db39eb06ed75459a43b7fb8337e40ec5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= <1064425721@qq.com>
Date: Wed, 11 Dec 2024 19:32:05 +0800
Subject: [PATCH] fix: `prettier` quit unexpectedly and lint code (#1676)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* fix: `prettier` quit unexpectedly and lint code
chore: suppress deprecation notice of tsconfig `suppressImplicitAnyIndexErrors`
* chore: 忽略 `helper/**` 文件
---
.eslintignore | 2 +
.github/workflows/issue-label.yml | 2 +-
.github/workflows/pr-comment-ci.yml | 2 +-
.prettierignore | 1 +
helper/attributes.json | 2 +-
helper/tags.json | 2 +-
package.json | 8 +-
src/date-time-picker/__test__/index.test.jsx | 16 +--
src/dropdown-menu/__test__/index.test.jsx | 10 +-
src/fab/props.ts | 2 +-
src/grid/__test__/index.test.jsx | 4 +-
src/input/__test__/index.test.jsx | 33 ++++--
src/layout/__test__/index.test.jsx | 1 -
src/link/__test__/index.test.jsx | 4 +-
src/loading/__test__/index.test.jsx | 1 -
src/navbar/__test__/index.test.jsx | 18 +--
src/notice-bar/__test__/index.test.jsx | 13 ++-
src/rate/__test__/index.test.jsx | 8 +-
src/search/__test__/index.test.jsx | 6 +-
src/shared/useTest/index.ts | 2 +-
src/slider/__test__/index.test.jsx | 92 +++++++--------
src/swipe-cell/__test__/index.test.jsx | 116 +++++++++++--------
src/swipe-cell/demos/left.vue | 2 +-
src/tab-bar/__test__/index.test.jsx | 14 ++-
src/table/base-table.tsx | 4 +-
src/tabs/__test__/index.test.jsx | 65 +++++------
src/tag/__test__/index.test.jsx | 34 +++---
tsconfig.json | 5 +-
28 files changed, 252 insertions(+), 217 deletions(-)
create mode 100644 .prettierignore
diff --git a/.eslintignore b/.eslintignore
index 9cfb3d4fe..6c4407c76 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -16,3 +16,5 @@ yarn-error.log
vitest.config.js
test
+
+helper/**
diff --git a/.github/workflows/issue-label.yml b/.github/workflows/issue-label.yml
index ec009a0c0..ad140ba3d 100644
--- a/.github/workflows/issue-label.yml
+++ b/.github/workflows/issue-label.yml
@@ -47,4 +47,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: ${{ steps.template.outputs.result }}
- update-mode: 'append'
\ No newline at end of file
+ update-mode: 'append'
diff --git a/.github/workflows/pr-comment-ci.yml b/.github/workflows/pr-comment-ci.yml
index 88cb71c0d..29db963e6 100644
--- a/.github/workflows/pr-comment-ci.yml
+++ b/.github/workflows/pr-comment-ci.yml
@@ -244,7 +244,7 @@ jobs:
git commit -m "chore: update snapshot"
fi
git status
-
+
- name: git push
run: |
git status
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 000000000..d505b2afc
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1 @@
+helper/**
\ No newline at end of file
diff --git a/helper/attributes.json b/helper/attributes.json
index b3d8bd7f8..59d334fa3 100644
--- a/helper/attributes.json
+++ b/helper/attributes.json
@@ -3894,4 +3894,4 @@
"type": "Number",
"description": "水印元素的 `z-index`,默认值写在 CSS 中\n\n[docs](https://tdesign.tencent.com/mobile-vue/components/watermark?tab=api#watermark-props)"
}
-}
\ No newline at end of file
+}
diff --git a/helper/tags.json b/helper/tags.json
index ac2e22842..2f3be96a8 100644
--- a/helper/tags.json
+++ b/helper/tags.json
@@ -1307,4 +1307,4 @@
],
"description": "Watermark\n\n水印\n\n[docs](https://tdesign.tencent.com/mobile-vue/components/watermark)"
}
-}
\ No newline at end of file
+}
diff --git a/package.json b/package.json
index 9179f1e6d..85dca43ec 100644
--- a/package.json
+++ b/package.json
@@ -44,7 +44,7 @@
"lint:tsc": "vue-tsc --emitDeclarationOnly",
"lint:fix": "npm run lint:fix-prettier && npm run lint:fix-eslint",
"lint:fix-eslint": "eslint --ext .vue,.ts,.tsx ./ --max-warnings 0 --ignore-path .gitignore --ignore-path .eslintignore --fix",
- "lint:fix-prettier": "prettier ./ --ignore-path .gitignore --ignore-path .eslintignore --write './*.{vue,ts,tsx}' --ignore-unknown",
+ "lint:fix-prettier": "prettier ./ --ignore-path .gitignore --ignore-path .eslintignore --ignore-path .prettierignore --write './*.{vue,ts,tsx}' --ignore-unknown",
"lint:vue": "vue-tsc --noEmit -p tsconfig.build.json",
"generate:coverage-badge": "npm run test:unit-coverage && node scripts/test/generate-coverage.js",
"update:css": "node scripts/generate-css-vars.js",
@@ -142,9 +142,9 @@
"esbuild": "^0.14.3",
"eslint": "^8.4.0",
"eslint-config-airbnb-base": "^15.0.0",
- "eslint-config-prettier": "^8.3.0",
+ "eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.25.3",
- "eslint-plugin-prettier": "^4.0.0",
+ "eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-vue": "^8.2.0",
"gray-matter": "^4.0.3",
"husky": "^6.0.0",
@@ -153,7 +153,7 @@
"lint-staged": "^10.5.4",
"mockdate": "^3.0.5",
"postcss": "^8.2.1",
- "prettier": "^2.5.1",
+ "prettier": "^3.4.2",
"prismjs": "^1.23.0",
"qrcode.vue": "^3.2.2",
"regenerator-runtime": "^0.13.9",
diff --git a/src/date-time-picker/__test__/index.test.jsx b/src/date-time-picker/__test__/index.test.jsx
index 91db7be67..840997fcf 100644
--- a/src/date-time-picker/__test__/index.test.jsx
+++ b/src/date-time-picker/__test__/index.test.jsx
@@ -114,7 +114,7 @@ describe('DateTimePicker', () => {
defaultValue: defaultDateTime,
title: 'mode 测试',
mode: ['date', 'second'],
- onPick
+ onPick,
},
});
// mode = ['date', 'second'], 渲染年月日时分秒,6列
@@ -136,11 +136,11 @@ describe('DateTimePicker', () => {
value: '10:00:00',
mode: [null, 'second'],
format: 'HH:mm:ss',
- start: '2023-06-13'
+ start: '2023-06-13',
},
});
- expect(wrapper.vm.value).toStrictEqual('10:00:00')
- })
+ expect(wrapper.vm.value).toStrictEqual('10:00:00');
+ });
it(': start && end ', async () => {
const start = '2020-6-30 10:00:00';
@@ -153,7 +153,7 @@ describe('DateTimePicker', () => {
value: start,
start,
end,
- mode: 'second'
+ mode: 'second',
},
});
const $pickerItems = wrapper.findAllComponents(PickerItem);
@@ -164,12 +164,12 @@ describe('DateTimePicker', () => {
expect(res[precisionRankRecord[0]].length).toEqual(endYear - startYear + 1);
// 设置到最后一天
- await wrapper.setProps({ value: end })
+ await wrapper.setProps({ value: end });
$pickerItems.forEach((item, index) => {
const { length } = item.findAll(`.${prefix}-picker-item__item`);
- const counter = [6, 10, 10, 11, 11, 11]
- expect(length).toBe(counter[index])
+ const counter = [6, 10, 10, 11, 11, 11];
+ expect(length).toBe(counter[index]);
});
});
diff --git a/src/dropdown-menu/__test__/index.test.jsx b/src/dropdown-menu/__test__/index.test.jsx
index 5f4f599cf..61225a92d 100644
--- a/src/dropdown-menu/__test__/index.test.jsx
+++ b/src/dropdown-menu/__test__/index.test.jsx
@@ -29,7 +29,6 @@ options.push({
describe('dropdown-menu', () => {
describe('props', () => {
-
it(': button', async () => {
// 底部 button 仅在 multiple/optionsLayout === 'tree'时,有效
const value1 = ref(['option_1']);
@@ -143,7 +142,6 @@ describe('dropdown-menu', () => {
const value1 = ref('option_2');
const value2 = ref('option_2');
-
const options2 = emptyArr.map((_, i) => ({
name: `选项${chineseMap[i]}`,
val: `option_${i}`,
@@ -236,11 +234,7 @@ describe('dropdown-menu', () => {
item.trigger('click', { item, index });
});
await sleep(200);
- expect(
- wrapper
- .find(`.${prefix}-dropdown-item__content`)
- .attributes('class')
- ).toBeTruthy();
+ expect(wrapper.find(`.${prefix}-dropdown-item__content`).attributes('class')).toBeTruthy();
});
it(': onChange', async () => {
@@ -347,4 +341,4 @@ describe('dropdown-menu', () => {
expect(onConfirm).toHaveBeenCalledTimes(1);
});
});
-});
\ No newline at end of file
+});
diff --git a/src/fab/props.ts b/src/fab/props.ts
index 84df9a371..d0a5e5181 100644
--- a/src/fab/props.ts
+++ b/src/fab/props.ts
@@ -32,5 +32,5 @@ export default {
draggable: {
type: Boolean,
default: false,
- }
+ },
};
diff --git a/src/grid/__test__/index.test.jsx b/src/grid/__test__/index.test.jsx
index 205260f07..03a3bcb5f 100644
--- a/src/grid/__test__/index.test.jsx
+++ b/src/grid/__test__/index.test.jsx
@@ -181,8 +181,8 @@ describe('grid-item', () => {
);
});
- if (l) {
- expect(wrapper.find('.t-grid-item').classes()).toContain(`t-grid-item--${l}`);
+ if (l) {
+ expect(wrapper.find('.t-grid-item').classes()).toContain(`t-grid-item--${l}`);
}
});
});
diff --git a/src/input/__test__/index.test.jsx b/src/input/__test__/index.test.jsx
index 370b36a8a..1ca5459f5 100644
--- a/src/input/__test__/index.test.jsx
+++ b/src/input/__test__/index.test.jsx
@@ -142,7 +142,7 @@ describe('Input.vue', async () => {
});
it(': type=password and disabled', async () => {
- const wrapper = mount();
+ const wrapper = mount();
expect(wrapper.find('.t-icon-browse-off').exists()).toBeTruthy();
wrapper.find('.t-icon-browse-off').trigger('click');
await wrapper.vm.$nextTick();
@@ -163,7 +163,7 @@ describe('Input.vue', async () => {
it(': autofocus', async () => {
const value = ref('123');
- const wrapper = mount();
+ const wrapper = mount();
await wrapper.vm.$nextTick();
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeTruthy();
wrapper.vm.blur();
@@ -172,13 +172,14 @@ describe('Input.vue', async () => {
wrapper.vm.focus();
await wrapper.vm.$nextTick();
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeTruthy();
-
});
it(': clearTrigger=always', async () => {
const value = ref('123');
const handleClear = vi.fn();
- const wrapper = mount();
+ const wrapper = mount(
+ ,
+ );
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeTruthy();
await wrapper.find('.t-icon-close-circle-filled').trigger('touchend');
expect(value.value).toBe('');
@@ -188,7 +189,9 @@ describe('Input.vue', async () => {
it(': clearTrigger=always and disabled', async () => {
const value = ref('123');
const handleClear = vi.fn();
- const wrapper = mount();
+ const wrapper = mount(
+ ,
+ );
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeFalsy();
await wrapper.setProps({
disabled: false,
@@ -199,7 +202,9 @@ describe('Input.vue', async () => {
it(': clearTrigger=always and readonly', async () => {
const value = ref('123');
const handleClear = vi.fn();
- const wrapper = mount();
+ const wrapper = mount(
+ ,
+ );
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeFalsy();
await wrapper.setProps({
readonly: false,
@@ -210,12 +215,14 @@ describe('Input.vue', async () => {
it(': clearTrigger=focus', async () => {
const value = ref('123');
const handleClear = vi.fn();
- const wrapper = mount();
+ const wrapper = mount(
+ ,
+ );
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeFalsy();
wrapper.vm.focus();
await wrapper.vm.$nextTick();
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeTruthy();
-
+
await wrapper.find('.t-icon-close-circle-filled').trigger('touchend');
expect(value.value).toBe('');
expect(handleClear).toBeCalled();
@@ -224,7 +231,9 @@ describe('Input.vue', async () => {
it(': clearTrigger=focus and disabled', async () => {
const value = ref('123');
const handleClear = vi.fn();
- const wrapper = mount();
+ const wrapper = mount(
+ ,
+ );
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeFalsy();
wrapper.vm.focus();
await wrapper.vm.$nextTick();
@@ -240,7 +249,9 @@ describe('Input.vue', async () => {
it(': clearTrigger=focus and readonly', async () => {
const value = ref('123');
const handleClear = vi.fn();
- const wrapper = mount();
+ const wrapper = mount(
+ ,
+ );
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeFalsy();
wrapper.vm.focus();
await wrapper.vm.$nextTick();
@@ -252,8 +263,6 @@ describe('Input.vue', async () => {
await wrapper.vm.$nextTick();
expect(wrapper.find('.t-icon-close-circle-filled').exists()).toBeTruthy();
});
-
-
});
describe('event', async () => {
it(': focus && blur', async () => {
diff --git a/src/layout/__test__/index.test.jsx b/src/layout/__test__/index.test.jsx
index 20ee91d7f..4c83bd1de 100644
--- a/src/layout/__test__/index.test.jsx
+++ b/src/layout/__test__/index.test.jsx
@@ -51,4 +51,3 @@ describe('col', () => {
});
});
});
-
diff --git a/src/link/__test__/index.test.jsx b/src/link/__test__/index.test.jsx
index f3b7693fc..f1ef05a5d 100644
--- a/src/link/__test__/index.test.jsx
+++ b/src/link/__test__/index.test.jsx
@@ -87,8 +87,8 @@ describe('Link', () => {
expect(wrapper.find('.t-link--content')).toBeTruthy();
});
it('prefixIcon', () => {
- const wrapper = mount(() => }>text)
- expect(wrapper.findComponent(Icon)).toBeTruthy()
+ const wrapper = mount(() => }>text);
+ expect(wrapper.findComponent(Icon)).toBeTruthy();
});
});
diff --git a/src/loading/__test__/index.test.jsx b/src/loading/__test__/index.test.jsx
index 5ce8b6a35..7fc61502e 100644
--- a/src/loading/__test__/index.test.jsx
+++ b/src/loading/__test__/index.test.jsx
@@ -11,7 +11,6 @@ const sleep = (duration) =>
}, duration),
);
-
describe('Loading.vue', () => {
describe('props', () => {
it(':delay', () => {
diff --git a/src/navbar/__test__/index.test.jsx b/src/navbar/__test__/index.test.jsx
index 5ead22e74..3db857787 100644
--- a/src/navbar/__test__/index.test.jsx
+++ b/src/navbar/__test__/index.test.jsx
@@ -9,10 +9,10 @@ describe('navbar', () => {
describe('props', () => {
it('fixed', async () => {
const navbar = mount();
- expect(navbar.element.style.position).toBe('fixed')
+ expect(navbar.element.style.position).toBe('fixed');
await navbar.setProps({ fixed: false });
- expect(navbar.element.style.position).toBe('relative')
+ expect(navbar.element.style.position).toBe('relative');
});
it('leftArrow', () => {
@@ -54,7 +54,7 @@ describe('navbar', () => {
const wrapper = mount(, {
// 插槽名称必须要和组件内部保持一致'left'
slots: {
- 'left': iconFunc,
+ left: iconFunc,
},
});
expect(wrapper.element).toMatchSnapshot();
@@ -69,7 +69,7 @@ describe('navbar', () => {
const wrapper = mount(, {
// 插槽名称必须要和组件内部保持一致'right'
slots: {
- 'right': iconFunc,
+ right: iconFunc,
},
});
expect(wrapper.element).toMatchSnapshot();
@@ -107,10 +107,10 @@ describe('navbar', () => {
describe('slots', () => {
it('left', () => {
- const slot =
左侧内容
;
+ const slot = 左侧内容
;
const navbar = mount(, {
slots: {
- 'left': slot,
+ left: slot,
},
});
expect(navbar.find('.t-navbar__left').find('.left-content').exists()).toBeTruthy();
@@ -119,17 +119,17 @@ describe('navbar', () => {
it('capsule', () => {
const navbar = mount(, {
slots: {
- 'capsule': iconFunc,
+ capsule: iconFunc,
},
});
expect(navbar.find('.t-navbar__capsule').exists()).toBeTruthy();
});
it('right', () => {
- const slot = 右侧内容
;
+ const slot = 右侧内容
;
const navbar = mount(, {
slots: {
- 'right': slot,
+ right: slot,
},
});
expect(navbar.find('.t-navbar__right').find('.right-content').exists()).toBeTruthy();
diff --git a/src/notice-bar/__test__/index.test.jsx b/src/notice-bar/__test__/index.test.jsx
index d8788738e..b5e93ef63 100644
--- a/src/notice-bar/__test__/index.test.jsx
+++ b/src/notice-bar/__test__/index.test.jsx
@@ -39,7 +39,6 @@ describe('NoticeBar', async () => {
await nextTick();
// expect(wrapper3.vm.scroll.marquee).toBe(false);
-
params.loop = 3;
const wrapper4 = mount();
await nextTick();
@@ -97,7 +96,7 @@ describe('NoticeBar', async () => {
it('direction', async () => {
const content = ['君不见', '高堂明镜悲白发', '朝如青丝暮成雪', '人生得意须尽欢', '莫使金樽空对月'];
- const wrapper = mount();
+ const wrapper = mount();
await nextTick();
expect(wrapper.find('.t-notice-bar__content--vertical').exists()).toBe(true);
});
@@ -156,7 +155,15 @@ describe('NoticeBar', async () => {
triggerName = name;
});
const wrapper = mount(
- ,
+ ,
);
await wrapper.find('.t-notice-bar__prefix-icon').trigger('click');
expect(triggerName).toBe('prefix-icon');
diff --git a/src/rate/__test__/index.test.jsx b/src/rate/__test__/index.test.jsx
index 7303fb3a0..58f004e73 100644
--- a/src/rate/__test__/index.test.jsx
+++ b/src/rate/__test__/index.test.jsx
@@ -135,7 +135,7 @@ describe('Rate', () => {
expect(onChange).toHaveBeenCalledTimes(1);
});
- it(': placement',async () => {
+ it(': placement', async () => {
const wrapper = mount(() => );
const icons = wrapper.findAll(`.${name}__icon`);
await icons[0].trigger('click');
@@ -145,7 +145,7 @@ describe('Rate', () => {
expect(placement.exists()).toBeTruthy();
});
- it(': placement=top',async () => {
+ it(': placement=top', async () => {
const wrapper = mount(() => );
const icons = wrapper.findAll(`.${name}__icon`);
await icons[0].trigger('click');
@@ -155,7 +155,7 @@ describe('Rate', () => {
expect(placement.exists()).toBeTruthy();
});
- it(': placement=bottom',async () => {
+ it(': placement=bottom', async () => {
const wrapper = mount(() => );
const icons = wrapper.findAll(`.${name}__icon`);
await icons[0].trigger('click');
@@ -165,7 +165,7 @@ describe('Rate', () => {
expect(placement.exists()).toBeTruthy();
});
- it(': placement=""',async () => {
+ it(': placement=""', async () => {
const wrapper = mount(() => );
const icons = wrapper.findAll(`.${name}__icon`);
await icons[0].trigger('click');
diff --git a/src/search/__test__/index.test.jsx b/src/search/__test__/index.test.jsx
index f10aa4496..7a3035553 100644
--- a/src/search/__test__/index.test.jsx
+++ b/src/search/__test__/index.test.jsx
@@ -145,8 +145,8 @@ describe('search', () => {
const action = '插槽';
const wrapper = mount(Search, {
- props:{
- value: 'test'
+ props: {
+ value: 'test',
},
slots: {
action,
@@ -154,7 +154,7 @@ describe('search', () => {
});
// TODO: 插槽实现的 dom 结构不正确,后期另提 pr 修复
const $search = wrapper.find(`.${name}`);
-
+
expect($search.text()).toEqual(action);
});
diff --git a/src/shared/useTest/index.ts b/src/shared/useTest/index.ts
index d35df3c0b..1128b8d57 100644
--- a/src/shared/useTest/index.ts
+++ b/src/shared/useTest/index.ts
@@ -25,7 +25,7 @@ export function useTestUtils() {
/**
* 测试相关的vitest方法
*/
-export function useVitest(vi: typeof import('vitest')['vitest']) {
+export function useVitest(vi: (typeof import('vitest'))['vitest']) {
const getBoundingClientRect = (dom: Element) => vi.spyOn(dom, 'getBoundingClientRect');
return { getBoundingClientRect };
diff --git a/src/slider/__test__/index.test.jsx b/src/slider/__test__/index.test.jsx
index 8dc30f048..8b2b546ae 100644
--- a/src/slider/__test__/index.test.jsx
+++ b/src/slider/__test__/index.test.jsx
@@ -78,16 +78,16 @@ describe('slider', () => {
},
});
const original = window.HTMLElement.prototype.getBoundingClientRect;
-
- await wrapper.setProps({ value: [0, 80]})
- expect(wrapper.find('.t-slider__line--default').attributes('style').includes(`right: 68px`)).toBeTruthy()
- expect(wrapper.find('.t-slider__dot--left').text()).toBe('0')
- expect(wrapper.find('.t-slider__dot--right').text()).toBe('80')
+ await wrapper.setProps({ value: [0, 80] });
+
+ expect(wrapper.find('.t-slider__line--default').attributes('style').includes(`right: 68px`)).toBeTruthy();
+ expect(wrapper.find('.t-slider__dot--left').text()).toBe('0');
+ expect(wrapper.find('.t-slider__dot--right').text()).toBe('80');
// restore
window.HTMLElement.prototype.getBoundingClientRect = original;
- })
+ });
it(':value out of limit', async () => {
const onChange = vi.fn();
@@ -95,32 +95,32 @@ describe('slider', () => {
const right = 359;
const { round } = Math;
const original = window.HTMLElement.prototype.getBoundingClientRect;
- const calcValue = (posX) => round((posX - left) / (right - left) * 100);
+ const calcValue = (posX) => round(((posX - left) / (right - left)) * 100);
window.HTMLElement.prototype.getBoundingClientRect = () => ({ left, right });
const wrapper = mount(Slider, {
props: {
value: [-1, 101],
onChange,
- range: true
+ range: true,
},
});
- const $line = wrapper.find('.t-slider__line')
- await $line.trigger('click', { clientX: 200 })
- expect(onChange).toHaveBeenCalledWith([0, calcValue(200)])
+ const $line = wrapper.find('.t-slider__line');
+ await $line.trigger('click', { clientX: 200 });
+ expect(onChange).toHaveBeenCalledWith([0, calcValue(200)]);
- await wrapper.setProps({ value: [-1, 101]})
+ await wrapper.setProps({ value: [-1, 101] });
// // restore
window.HTMLElement.prototype.getBoundingClientRect = original;
// mock dot bounding client rect
const $leftDot = wrapper.find('.t-slider__dot--left');
const $rightDot = wrapper.find('.t-slider__dot--right');
- vi.spyOn($leftDot.wrapperElement, 'getBoundingClientRect').mockReturnValue({ left: 16 })
- vi.spyOn($rightDot.wrapperElement, 'getBoundingClientRect').mockReturnValue({ left: 359 })
- await $line.trigger('click', { clientX: 50 })
- expect(onChange).toHaveBeenLastCalledWith([calcValue(50), 100])
- })
+ vi.spyOn($leftDot.wrapperElement, 'getBoundingClientRect').mockReturnValue({ left: 16 });
+ vi.spyOn($rightDot.wrapperElement, 'getBoundingClientRect').mockReturnValue({ left: 359 });
+ await $line.trigger('click', { clientX: 50 });
+ expect(onChange).toHaveBeenLastCalledWith([calcValue(50), 100]);
+ });
it(':capsule theme', async () => {
const onChange = vi.fn();
@@ -134,19 +134,19 @@ describe('slider', () => {
props: {
value: 0,
onChange,
- theme: 'capsule'
+ theme: 'capsule',
},
});
-
- const $line = wrapper.find('.t-slider__line')
-
- await $line.trigger('click', { clientX })
- expect(onChange).toHaveBeenCalledWith(61)
-
+ const $line = wrapper.find('.t-slider__line');
+
+ await $line.trigger('click', { clientX });
+
+ expect(onChange).toHaveBeenCalledWith(61);
+
// // restore
window.HTMLElement.prototype.getBoundingClientRect = original;
- })
+ });
});
describe('event', () => {
@@ -175,7 +175,7 @@ describe('slider', () => {
const clientX = 200;
const { round } = Math;
const original = window.HTMLElement.prototype.getBoundingClientRect;
- const calcValue = (posX) => round((posX - left) / (right - left) * 100);
+ const calcValue = (posX) => round(((posX - left) / (right - left)) * 100);
window.HTMLElement.prototype.getBoundingClientRect = () => ({ left, right });
const wrapper = mount(Slider, {
@@ -184,21 +184,21 @@ describe('slider', () => {
onChange,
},
});
-
- const $line = wrapper.find('.t-slider__line')
- const $dot = wrapper.find('.t-slider__dot')
- await $line.trigger('click', { clientX })
+ const $line = wrapper.find('.t-slider__line');
+ const $dot = wrapper.find('.t-slider__dot');
+
+ await $line.trigger('click', { clientX });
- expect(onChange).toHaveBeenCalledWith(calcValue(clientX))
-
- await move($dot,100);
+ expect(onChange).toHaveBeenCalledWith(calcValue(clientX));
- expect(onChange).toHaveBeenCalledWith(calcValue(100))
+ await move($dot, 100);
+
+ expect(onChange).toHaveBeenCalledWith(calcValue(100));
// restore
window.HTMLElement.prototype.getBoundingClientRect = original;
- })
+ });
it('@touch', async () => {
const onChange = vi.fn();
@@ -213,22 +213,22 @@ describe('slider', () => {
props: {
value: [0, 100],
onChange,
- range: true
+ range: true,
},
});
-
- const $leftDot = wrapper.find('.t-slider__dot--left')
- const $rightDot = wrapper.find('.t-slider__dot--right')
-
+
+ const $leftDot = wrapper.find('.t-slider__dot--left');
+ const $rightDot = wrapper.find('.t-slider__dot--right');
+
await move($leftDot, 100);
- const leftValue = round((100 - left) / (right - left) * 100);
- expect(onChange).toHaveBeenCalledWith([leftValue, 100])
+ const leftValue = round(((100 - left) / (right - left)) * 100);
+ expect(onChange).toHaveBeenCalledWith([leftValue, 100]);
- await move($rightDot, 300)
- const rightValue = round((300 - left) / (right - left) * 100);
- expect(onChange).toHaveBeenCalledWith([0, rightValue])
+ await move($rightDot, 300);
+ const rightValue = round(((300 - left) / (right - left)) * 100);
+ expect(onChange).toHaveBeenCalledWith([0, rightValue]);
// restore
window.HTMLElement.prototype.getBoundingClientRect = original;
- })
+ });
});
});
diff --git a/src/swipe-cell/__test__/index.test.jsx b/src/swipe-cell/__test__/index.test.jsx
index 63ff06b4a..f92eaf74d 100644
--- a/src/swipe-cell/__test__/index.test.jsx
+++ b/src/swipe-cell/__test__/index.test.jsx
@@ -23,51 +23,53 @@ describe('swipe-cell', () => {
});
// it(': disabled', async () => {
- // const swipeAction = [{ text: '编辑', className: 't-button--primary',style: 'width: 60px' }];
-
- // const content = 'content is a string';
- // const wrapper = mount(SwipeCell, {
- // props: {
- // content,
- // right: swipeAction,
- // },
- // });
- // wrapper.vm.$nextTick();
- // const $target = wrapper.find('.t-swipe-cell__wrapper');
- // // disabled = true, 滑动操作无效
- // await wrapper.setProps({ disabled: true });
- // let touchend = await move($target);
- // //wrapper.find('.t-swipe-cell__wrapper').element.style.transform
- // touchend();
- // expect(wrapper.vm.initData.moving).toBe(false);
-
- // disabled = false, 开启滑动操作
- // await wrapper.setProps({ disabled: false });
- // console.log(wrapper.find('.t-swipe-cell__wrapper').element.style.transform);
- // touchend = await move($target);
- // await move($target,-120);
- // wrapper.vm.$nextTick();
- // expect(wrapper.vm.initData.moving).toBe(true);
- //
-
- // console.log(wrapper.find('.t-swipe-cell__wrapper').element.style.transform);
- // expect(wrapper.vm.initData.moving).toBe(false);
-
- // wrapper.unmount();
- // touchend = await move($target);
- // expect(wrapper.vm.initData.moving).toBe(false);
- // touchend();
- // expect(wrapper.vm.initData.moving).toBe(false);
+ // const swipeAction = [{ text: '编辑', className: 't-button--primary',style: 'width: 60px' }];
+
+ // const content = 'content is a string';
+ // const wrapper = mount(SwipeCell, {
+ // props: {
+ // content,
+ // right: swipeAction,
+ // },
+ // });
+ // wrapper.vm.$nextTick();
+ // const $target = wrapper.find('.t-swipe-cell__wrapper');
+ // // disabled = true, 滑动操作无效
+ // await wrapper.setProps({ disabled: true });
+ // let touchend = await move($target);
+ // //wrapper.find('.t-swipe-cell__wrapper').element.style.transform
+ // touchend();
+ // expect(wrapper.vm.initData.moving).toBe(false);
+
+ // disabled = false, 开启滑动操作
+ // await wrapper.setProps({ disabled: false });
+ // console.log(wrapper.find('.t-swipe-cell__wrapper').element.style.transform);
+ // touchend = await move($target);
+ // await move($target,-120);
+ // wrapper.vm.$nextTick();
+ // expect(wrapper.vm.initData.moving).toBe(true);
+ //
+
+ // console.log(wrapper.find('.t-swipe-cell__wrapper').element.style.transform);
+ // expect(wrapper.vm.initData.moving).toBe(false);
+
+ // wrapper.unmount();
+ // touchend = await move($target);
+ // expect(wrapper.vm.initData.moving).toBe(false);
+ // touchend();
+ // expect(wrapper.vm.initData.moving).toBe(false);
// });
it(': left', async () => {
const onClick = vi.fn();
const onChange = vi.fn();
- const swipeAction = [{
- icon: ,
- text: '编辑',
- className: 't-button--primary',
- sure: 'sure-confirm'
- }];
+ const swipeAction = [
+ {
+ icon: ,
+ text: '编辑',
+ className: 't-button--primary',
+ sure: 'sure-confirm',
+ },
+ ];
const content = 'content is a string';
const wrapper = mount(SwipeCell, {
@@ -78,7 +80,11 @@ describe('swipe-cell', () => {
onChange,
},
slots: {
- 'sure-confirm': () =>
+ 'sure-confirm': () => (
+
+
+
+ ),
},
});
@@ -95,14 +101,13 @@ describe('swipe-cell', () => {
const $sure = wrapper.find('.t-button--primary_sure');
expect($sure.exists()).toBeTruthy();
// expect(wrapper.vm.showSureLeft).toBe(true);
-
+
// const $target = wrapper.find('.t-swipe-cell__content');
// let touchend = await move($target);
// expect(wrapper.vm.initData.moving).toBe(true);
// await touchend();
// expect(wrapper.vm.initData.moving).toBe(false);
// expect(wrapper.vm.showSureLeft).toBe(false);
-
});
// it(': opened', async () => {
// const onClick = vi.fn();
@@ -150,7 +155,15 @@ describe('swipe-cell', () => {
const onChange = vi.fn();
const swipeAction = [
{ text: '默认', className: 't-button--primary' },
- { text: '删除', className: 't-button--danger', sure:
},
+ {
+ text: '删除',
+ className: 't-button--danger',
+ sure: (
+
+
+
+ ),
+ },
];
const content = 'content is a string';
@@ -174,7 +187,6 @@ describe('swipe-cell', () => {
// expect(onChange).toBeCalledTimes(2);
// expect(onChange).toHaveBeenCalledWith(undefined);
-
await $buttons.at(1).trigger('click');
expect(onClick).toBeCalledTimes(1);
// expect(onChange).toBeCalledTimes(2);
@@ -256,7 +268,11 @@ describe('swipe-cell', () => {
});
it(': left', async () => {
const onClick = vi.fn();
- const left = () => 删除
;
+ const left = () => (
+
+ 删除
+
+ );
const content = 'content is a string';
const wrapper = mount(SwipeCell, {
slots: {
@@ -275,7 +291,11 @@ describe('swipe-cell', () => {
});
it(': right', async () => {
const onClick = vi.fn();
- const right = () => 删除
;
+ const right = () => (
+
+ 删除
+
+ );
const content = 'content is a string';
const wrapper = mount(SwipeCell, {
slots: {
diff --git a/src/swipe-cell/demos/left.vue b/src/swipe-cell/demos/left.vue
index b35ed6708..eeff9c782 100644
--- a/src/swipe-cell/demos/left.vue
+++ b/src/swipe-cell/demos/left.vue
@@ -21,7 +21,7 @@
- handleClickBtns(value)">
+ handleClickBtns(value)">
diff --git a/src/tab-bar/__test__/index.test.jsx b/src/tab-bar/__test__/index.test.jsx
index 08e97cd69..6e66fb53c 100644
--- a/src/tab-bar/__test__/index.test.jsx
+++ b/src/tab-bar/__test__/index.test.jsx
@@ -90,15 +90,17 @@ describe('TabBar', () => {
it('item without value', async () => {
const wrapper = mount({
render() {
- return
-
-
- }
- })
+ return (
+
+
+
+ );
+ },
+ });
const item = wrapper.findComponent('.t-tab-bar-item');
// expect(item.vm.isChecked).toBeTruthy();
- })
+ });
});
describe('events', () => {
diff --git a/src/table/base-table.tsx b/src/table/base-table.tsx
index b5a948f07..bce9f12e8 100644
--- a/src/table/base-table.tsx
+++ b/src/table/base-table.tsx
@@ -193,9 +193,7 @@ export default defineComponent({
>
- {props.columns?.map((col_item) => (
-
- ))}
+ {props.columns?.map((col_item) => )}
{props.showHeader && (
diff --git a/src/tabs/__test__/index.test.jsx b/src/tabs/__test__/index.test.jsx
index c611afdad..dab40aa6d 100644
--- a/src/tabs/__test__/index.test.jsx
+++ b/src/tabs/__test__/index.test.jsx
@@ -26,15 +26,15 @@ const tabPanelList = [
value: '1',
label: '标签页一',
panel: '标签一内容区',
- destroyOnHide: false
+ destroyOnHide: false,
},
{
value: '2',
label: '标签页二',
panel: '标签二内容区',
- destroyOnHide: true
+ destroyOnHide: true,
},
-]
+];
describe('Tabs', () => {
describe('props', () => {
@@ -51,18 +51,17 @@ describe('Tabs', () => {
spaceEvenly: false,
});
- $tabNavItems.forEach(item => {
+ $tabNavItems.forEach((item) => {
expect(item.attributes('class').includes(`${prefix}-tabs-item-evenly`)).toBeTruthy();
});
-
});
it(': theme', async () => {
- let theme = ''
+ let theme = '';
const wrapper = mount(Tabs, {
props: {
- theme: theme
- }
+ theme: theme,
+ },
});
const navWrap = wrapper.find(`.${name}__wrapper`);
const $tabNavItems = navWrap.findAllComponents(TTabNav);
@@ -71,25 +70,25 @@ describe('Tabs', () => {
await wrapper.setProps({
theme,
});
- $tabNavItems.forEach(item => {
+ $tabNavItems.forEach((item) => {
expect($tabs.attributes('class').includes(`${prefix}-tabs-item-${theme}`)).toBeTruthy();
- })
+ });
theme = 'tag';
await wrapper.setProps({
theme,
});
- $tabNavItems.forEach(item => {
+ $tabNavItems.forEach((item) => {
expect($tabs.attributes('class').includes(`${prefix}-tabs-item-${theme}`)).toBeTruthy();
- })
+ });
theme = 'card';
await wrapper.setProps({
theme,
});
- $tabNavItems.forEach(item => {
+ $tabNavItems.forEach((item) => {
expect($tabs.attributes('class').includes(`${prefix}-tabs-item-${theme}`)).toBeTruthy();
- })
+ });
});
it(': animation', async () => {
@@ -124,7 +123,8 @@ describe('Tabs', () => {
$navLine
.attributes('style')
.includes(
- `transform: translateX(${navWidth * index + navWidth / 2 - linWidth / 2}px); transition-duration: ${animation.value
+ `transform: translateX(${navWidth * index + navWidth / 2 - linWidth / 2}px); transition-duration: ${
+ animation.value
}ms;`,
),
);
@@ -152,7 +152,7 @@ describe('Tabs', () => {
});
it(': size', async () => {
- let size = ''
+ let size = '';
const SIZE_CLASSNAMES = {
small: `${prefix}-size-s`,
medium: `${prefix}-size-m`,
@@ -160,8 +160,8 @@ describe('Tabs', () => {
};
const wrapper = mount(Tabs, {
props: {
- size: size
- }
+ size: size,
+ },
});
const $tabs = wrapper.findComponent(Tabs);
@@ -181,18 +181,14 @@ describe('Tabs', () => {
});
it(': showBottomLine', async () => {
- const currentValue = ref('1')
- const showBottomLine = ref(true)
+ const currentValue = ref('1');
+ const showBottomLine = ref(true);
const animation = ref({ duration: 500 });
const wrapper = mount({
setup() {
return () => (
-
+
{/*
*/}
{tabPanelList.map((item) => {
@@ -204,10 +200,10 @@ describe('Tabs', () => {
});
// 触发moveToActiveTab()
- currentValue.value = '2'
+ currentValue.value = '2';
// 等待组件异步更新样式
- await sleep(0)
+ await sleep(0);
const navWrap = wrapper.find(`.${name}__wrapper`);
const navLine = navWrap.find(`.${name}__track`);
@@ -217,7 +213,8 @@ describe('Tabs', () => {
navLine
.attributes('style')
.includes(
- `transform: translateX(${Number(tab.element.offsetLeft) + Number(tab.element.offsetWidth) / 2 - (navLine.element.offsetWidth) / 2
+ `transform: translateX(${
+ Number(tab.element.offsetLeft) + Number(tab.element.offsetWidth) / 2 - navLine.element.offsetWidth / 2
}px); ${animation.value ? `transition-duration: ${animation.value.duration}ms` : ''}`,
),
).toBeTruthy();
@@ -317,7 +314,7 @@ describe('Tabs', () => {
it(': click', async () => {
const currentValue = ref('1');
- const currentLabel = ref('')
+ const currentLabel = ref('');
const onClick = vi.fn((value, label) => {
currentValue.value = value;
currentLabel.value = label;
@@ -346,8 +343,8 @@ describe('Tabs', () => {
});
it(': scroll', async () => {
- const sticky = true
- const stickyProps = ref({ zIndex: 99 })
+ const sticky = true;
+ const stickyProps = ref({ zIndex: 99 });
const onScroll = vi.fn();
const wrapper = mount({
setup() {
@@ -359,9 +356,9 @@ describe('Tabs', () => {
);
},
});
- const $sticky = wrapper.findComponent(Sticky)
- await $sticky.trigger('scroll')
- expect(onScroll).toBeCalled()
+ const $sticky = wrapper.findComponent(Sticky);
+ await $sticky.trigger('scroll');
+ expect(onScroll).toBeCalled();
});
});
});
diff --git a/src/tag/__test__/index.test.jsx b/src/tag/__test__/index.test.jsx
index 13351e6e0..67e0a461b 100644
--- a/src/tag/__test__/index.test.jsx
+++ b/src/tag/__test__/index.test.jsx
@@ -23,9 +23,9 @@ describe('Tag.vue', async () => {
it('theme render', async () => {
themeList.forEach((t) => {
const wrapper = mount(() => {TEXT});
- if(!t) {
+ if (!t) {
expect(wrapper.classes()).toContain(`t-tag`);
- }else {
+ } else {
expect(wrapper.classes()).toContain(`t-tag--${t}`);
}
});
@@ -34,9 +34,9 @@ describe('Tag.vue', async () => {
it('variant render', async () => {
variantList.forEach((v) => {
const wrapper = mount(() => {TEXT});
- if(!v) {
+ if (!v) {
expect(wrapper.classes()).toContain(`t-tag--${'default'}`);
- }else {
+ } else {
expect(wrapper.classes()).toContain(`t-tag--${v}`);
}
});
@@ -45,7 +45,7 @@ describe('Tag.vue', async () => {
it('size render', async () => {
sizeList.forEach((s) => {
const wrapper = mount(() => {TEXT});
- if(!s) {
+ if (!s) {
expect(wrapper.classes()).toContain(`t-tag--${'default'}`);
} else {
expect(wrapper.classes()).toContain(`t-tag--${s}`);
@@ -56,9 +56,9 @@ describe('Tag.vue', async () => {
it('shape render', async () => {
shapeList.forEach((s) => {
const wrapper = mount(() => {TEXT});
- if(!s) {
+ if (!s) {
expect(wrapper.classes()).toContain(`t-tag--${'default'}`);
- }else {
+ } else {
expect(wrapper.classes()).toContain(`t-tag--${s}`);
}
});
@@ -87,14 +87,18 @@ describe('Tag.vue', async () => {
it('close render', async () => {
const onClose = vi.fn();
- const wrapper = mount(() => {TEXT});
+ const wrapper = mount(() => (
+
+ {TEXT}
+
+ ));
const com = wrapper.findComponent(Tag);
expect(wrapper.classes()).toContain('t-tag--closable');
const closeBtn = com.find('.t-tag__icon-close');
expect(closeBtn.exists()).toBeTruthy();
await closeBtn.trigger('click');
- expect(onClose).toBeCalledWith({ e: expect.any(MouseEvent)});
+ expect(onClose).toBeCalledWith({ e: expect.any(MouseEvent) });
});
});
@@ -146,9 +150,9 @@ describe('CheckTag render', async () => {
it('variant render', async () => {
variantList.forEach((v) => {
const wrapper = mount(() => {TEXT});
- if(!v) {
+ if (!v) {
expect(wrapper.classes()).toContain(`t-tag--${'default'}`);
- }else {
+ } else {
expect(wrapper.classes()).toContain(`t-tag--${v}`);
}
});
@@ -182,13 +186,17 @@ describe('CheckTag render', async () => {
});
it('close render', async () => {
const onClose = vi.fn();
- const wrapper = mount(() => {TEXT});
+ const wrapper = mount(() => (
+
+ {TEXT}
+
+ ));
const com = wrapper.findComponent(TCheckTag);
expect(wrapper.classes()).toContain('t-tag--closable');
const closeBtn = com.find('.t-tag__icon-close');
expect(closeBtn.exists()).toBeTruthy();
await closeBtn.trigger('click');
- expect(onClose).toBeCalledWith({ e: expect.any(MouseEvent)});
+ expect(onClose).toBeCalledWith({ e: expect.any(MouseEvent) });
});
});
diff --git a/tsconfig.json b/tsconfig.json
index 86735ff8a..12241833a 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -10,6 +10,7 @@
"strictNullChecks": false,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
+ "ignoreDeprecations": "5.0",
"resolveJsonModule": true,
"importHelpers": true,
"isolatedModules": false,
@@ -25,9 +26,7 @@
"paths": {
"@/*": ["src/*"],
"tdesign-mobile-vue": ["src"],
- "tdesign-mobile-vue/es/locale/*": [
- "src/locale/*"
- ],
+ "tdesign-mobile-vue/es/locale/*": ["src/locale/*"]
},
"types": ["vitest/globals"],
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]