test(Field): should not modify the value if it's within the min/max (#13343)

Co-authored-by: dgmpk <465316497@qq.com>
Co-authored-by: neverland <jait.chen@foxmail.com>
This commit is contained in:
inottn
2025-02-09 20:51:34 +08:00
committed by GitHub
parent 507e397d07
commit c7024d4457
2 changed files with 18 additions and 0 deletions

View File

@@ -346,6 +346,7 @@ export default defineComponent({
props.min ?? -Infinity,
props.max ?? Infinity,
);
if (+value !== adjustedValue) {
value = adjustedValue.toString();
}

View File

@@ -123,6 +123,23 @@ test('should limit input value based on min and max props', async () => {
expect(wrapper.emitted('update:modelValue')[2][0]).toEqual('5');
});
test('should not modify the value if it is within the min/max', async () => {
const wrapper = mount(Field, {
props: {
type: 'number',
min: 2,
max: 10,
modelValue: '',
},
});
const input = wrapper.find('input');
await wrapper.setProps({ modelValue: '2.00' });
await input.trigger('blur');
expect(wrapper.emitted('update:modelValue')).toBeFalsy();
});
test('should render textarea when type is textarea', async () => {
const wrapper = mount(Field, {
props: {