feat(reactivity): ref(Ref) should return Ref (#180)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { ref, isRef } from '../src/ref'
|
||||
import { reactive, isReactive, toRaw, markNonReactive } from '../src/reactive'
|
||||
import { mockWarn } from '@vue/runtime-test'
|
||||
|
||||
@@ -126,6 +127,14 @@ describe('reactivity/reactive', () => {
|
||||
expect(toRaw(original)).toBe(original)
|
||||
})
|
||||
|
||||
test('should not unwrap Ref<T>', () => {
|
||||
const observedNumberRef = reactive(ref(1))
|
||||
const observedObjectRef = reactive(ref({ foo: 1 }))
|
||||
|
||||
expect(isRef(observedNumberRef)).toBe(true)
|
||||
expect(isRef(observedObjectRef)).toBe(true)
|
||||
})
|
||||
|
||||
test('non-observable values', () => {
|
||||
const assertValue = (value: any) => {
|
||||
reactive(value)
|
||||
|
||||
@@ -63,6 +63,13 @@ describe('reactivity/ref', () => {
|
||||
expect(dummy3).toBe(3)
|
||||
})
|
||||
|
||||
it('should unwrap nested ref in types', () => {
|
||||
const a = ref(0)
|
||||
const b = ref(a)
|
||||
|
||||
expect(typeof (b.value + 1)).toBe('number')
|
||||
})
|
||||
|
||||
it('should unwrap nested values in types', () => {
|
||||
const a = {
|
||||
b: ref(0)
|
||||
|
||||
Reference in New Issue
Block a user