feat(Field): fix render error when value is null or undefined (#6419)

This commit is contained in:
lazy1993 2020-05-30 20:34:52 +08:00 committed by GitHub
parent 754e8994a0
commit ba04660ed3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -491,7 +491,7 @@ export default createComponent({
genWordLimit() {
if (this.showWordLimit && this.maxlength) {
const count = this.value.length;
const count = (this.value || '').length;
const full = count >= this.maxlength;
return (

View File

@ -79,6 +79,24 @@ exports[`reach max word-limit 1`] = `
</div>
`;
exports[`reach max word-limit null 1`] = `
<div class="van-cell van-field">
<div class="van-cell__value van-cell__value--alone van-field__value">
<div class="van-field__body"><input type="text" class="van-field__control"></div>
<div class="van-field__word-limit"><span class="van-field__word-num">0</span>/3</div>
</div>
</div>
`;
exports[`reach max word-limit undefined 1`] = `
<div class="van-cell van-field">
<div class="van-cell__value van-cell__value--alone van-field__value">
<div class="van-field__body"><input type="text" class="van-field__control"></div>
<div class="van-field__word-limit"><span class="van-field__word-num">0</span>/3</div>
</div>
</div>
`;
exports[`render extra slot 1`] = `
<div class="van-cell van-field">
<div class="van-cell__value van-cell__value--alone van-field__value">

View File

@ -310,6 +310,28 @@ test('reach max word-limit', () => {
expect(wrapper).toMatchSnapshot();
});
test('reach max word-limit undefined', () => {
const wrapper = mount(Field, {
propsData: {
value: undefined,
maxlength: 3,
showWordLimit: true,
},
});
expect(wrapper).toMatchSnapshot();
});
test('reach max word-limit null', () => {
const wrapper = mount(Field, {
propsData: {
value: null,
maxlength: 3,
showWordLimit: true,
},
});
expect(wrapper).toMatchSnapshot();
});
test('name prop', () => {
const wrapper = mount(Field, {
propsData: {