test: test unwrapping computed refs

This commit is contained in:
Evan You
2019-10-14 11:21:09 -04:00
parent d8b2b9eb9c
commit 1c56d1bf19
3 changed files with 29 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
import { ref, isRef } from '../src/ref'
import { reactive, isReactive, toRaw, markNonReactive } from '../src/reactive'
import { mockWarn } from '@vue/runtime-test'
import { computed } from '../src/computed'
describe('reactivity/reactive', () => {
mockWarn()
@@ -135,6 +136,22 @@ describe('reactivity/reactive', () => {
expect(isRef(observedObjectRef)).toBe(true)
})
test('should unwrap computed refs', () => {
// readonly
const a = computed(() => 1)
// writable
const b = computed({
get: () => 1,
set: () => {}
})
const obj = reactive({ a, b })
// check type
obj.a + 1
obj.b + 1
expect(typeof obj.a).toBe(`number`)
expect(typeof obj.b).toBe(`number`)
})
test('non-observable values', () => {
const assertValue = (value: any) => {
reactive(value)