diff --git a/packages/components/select/__tests__/select.test.ts b/packages/components/select/__tests__/select.test.ts index c1d76a8e14..8a23aa6a7e 100644 --- a/packages/components/select/__tests__/select.test.ts +++ b/packages/components/select/__tests__/select.test.ts @@ -948,16 +948,9 @@ describe('Select', () => { const selectWrapper = wrapper.findComponent(Select) const inputWrapper = selectWrapper.findComponent({ ref: 'reference' }) const inputDom = inputWrapper.element - const inputRect = { - height: 40, - width: 221, - x: 44, - y: 8, - top: 8, - } const mockInputWidth = vi - .spyOn(inputDom, 'getBoundingClientRect') - .mockReturnValue(inputRect as DOMRect) + .spyOn(inputDom as HTMLElement, 'offsetWidth', 'get') + .mockReturnValue(200) selectWrapper.vm.handleResize() options[0].click() await nextTick() @@ -968,9 +961,9 @@ describe('Select', () => { const tagWrappers = wrapper.findAll('.el-select__tags-text') for (const tagWrapper of tagWrappers) { const tagWrapperDom = tagWrapper.element - expect( - Number.parseInt(tagWrapperDom.style.maxWidth) === inputRect.width - 75 - ).toBe(true) + expect(Number.parseInt(tagWrapperDom.style.maxWidth) === 200 - 75).toBe( + true + ) } mockInputWidth.mockRestore() }) @@ -1016,16 +1009,9 @@ describe('Select', () => { const selectWrapper = wrapper.findComponent(Select) const inputWrapper = selectWrapper.findComponent({ ref: 'reference' }) const inputDom = inputWrapper.element - const inputRect = { - height: 40, - width: 221, - x: 44, - y: 8, - top: 8, - } const mockInputWidth = vi - .spyOn(inputDom, 'getBoundingClientRect') - .mockReturnValue(inputRect as DOMRect) + .spyOn(inputDom as HTMLElement, 'offsetWidth', 'get') + .mockReturnValue(200) selectWrapper.vm.handleResize() options[0].click() await nextTick() @@ -1035,9 +1021,9 @@ describe('Select', () => { await nextTick() const tagWrappers = wrapper.findAll('.el-select__tags-text') const tagWrapperDom = tagWrappers[0].element - expect( - Number.parseInt(tagWrapperDom.style.maxWidth) === inputRect.width - 123 - ).toBe(true) + expect(Number.parseInt(tagWrapperDom.style.maxWidth) === 200 - 123).toBe( + true + ) mockInputWidth.mockRestore() }) diff --git a/packages/components/select/src/useSelect.ts b/packages/components/select/src/useSelect.ts index f2dea5bd33..55d8a283a4 100644 --- a/packages/components/select/src/useSelect.ts +++ b/packages/components/select/src/useSelect.ts @@ -561,7 +561,7 @@ export const useSelect = (props, states: States, ctx) => { } const resetInputWidth = () => { - states.inputWidth = reference.value?.$el.getBoundingClientRect().width + states.inputWidth = reference.value?.$el.offsetWidth } const onInputChange = () => {