feat(computed): add readonly flag if no setter is provided (#1654)
This commit is contained in:
@@ -4,7 +4,8 @@ import {
|
||||
effect,
|
||||
stop,
|
||||
ref,
|
||||
WritableComputedRef
|
||||
WritableComputedRef,
|
||||
isReadonly
|
||||
} from '../src'
|
||||
import { mockWarn } from '@vue/shared'
|
||||
|
||||
@@ -177,4 +178,22 @@ describe('reactivity/computed', () => {
|
||||
'Write operation failed: computed value is readonly'
|
||||
).toHaveBeenWarnedLast()
|
||||
})
|
||||
|
||||
it('should be readonly', () => {
|
||||
let a = { a: 1 }
|
||||
const x = computed(() => a)
|
||||
expect(isReadonly(x)).toBe(true)
|
||||
expect(isReadonly(x.value)).toBe(false)
|
||||
expect(isReadonly(x.value.a)).toBe(false)
|
||||
const z = computed<typeof a>({
|
||||
get() {
|
||||
return a
|
||||
},
|
||||
set(v) {
|
||||
a = v
|
||||
}
|
||||
})
|
||||
expect(isReadonly(z)).toBe(false)
|
||||
expect(isReadonly(z.value.a)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user