mirror of https://github.com/vuejs/core.git
fix(reactivity): clear method on readonly collections should return undefined (#7316)
This commit is contained in:
parent
6e0b068e92
commit
657476dcdb
|
|
@ -275,6 +275,14 @@ describe('reactivity/readonly', () => {
|
|||
expect(isReactive(value)).toBe(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('should return undefined from Map.clear() call', () => {
|
||||
const wrapped = readonly(new Collection())
|
||||
expect(wrapped.clear()).toBeUndefined()
|
||||
expect(
|
||||
`Clear operation failed: target is readonly.`
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
@ -332,6 +340,14 @@ describe('reactivity/readonly', () => {
|
|||
expect(isReadonly(v2)).toBe(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('should return undefined from Set.clear() call', () => {
|
||||
const wrapped = readonly(new Collection())
|
||||
expect(wrapped.clear()).toBeUndefined()
|
||||
expect(
|
||||
`Clear operation failed: target is readonly.`
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -113,6 +113,12 @@ describe('reactivity/shallowReadonly', () => {
|
|||
).not.toHaveBeenWarned()
|
||||
})
|
||||
})
|
||||
|
||||
test('should return undefined from Map.clear() call', () => {
|
||||
const sroMap = shallowReadonly(new Map())
|
||||
expect(sroMap.clear()).toBeUndefined()
|
||||
expect(`Clear operation failed: target is readonly.`).toHaveBeenWarned()
|
||||
})
|
||||
})
|
||||
|
||||
describe('collection/Set', () => {
|
||||
|
|
@ -197,5 +203,11 @@ describe('reactivity/shallowReadonly', () => {
|
|||
).not.toHaveBeenWarned()
|
||||
})
|
||||
})
|
||||
|
||||
test('should return undefined from Set.clear() call', () => {
|
||||
const sroSet = shallowReadonly(new Set())
|
||||
expect(sroSet.clear()).toBeUndefined()
|
||||
expect(`Clear operation failed: target is readonly.`).toHaveBeenWarned()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -223,7 +223,11 @@ function createReadonlyMethod(type: TriggerOpTypes): Function {
|
|||
toRaw(this)
|
||||
)
|
||||
}
|
||||
return type === TriggerOpTypes.DELETE ? false : this
|
||||
return type === TriggerOpTypes.DELETE
|
||||
? false
|
||||
: type === TriggerOpTypes.CLEAR
|
||||
? undefined
|
||||
: this
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue