]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(reactivity): add tests for reactive and non-reactive objects (#12576)
authorSunny <73089592+Sunny-117@users.noreply.github.com>
Thu, 20 Feb 2025 09:00:31 +0000 (17:00 +0800)
committerGitHub <noreply@github.com>
Thu, 20 Feb 2025 09:00:31 +0000 (17:00 +0800)
packages/reactivity/__tests__/reactive.spec.ts

index a23f2066f244b78dc2437de1b1ba664a1d8f2f9d..a3ba6a39c1d46a67c7b79dc8089453663693c222 100644 (file)
@@ -1,4 +1,4 @@
-import { isRef, ref } from '../src/ref'
+import { isRef, ref, shallowRef } from '../src/ref'
 import {
   isProxy,
   isReactive,
@@ -426,4 +426,17 @@ describe('reactivity/reactive', () => {
     map.set(void 0, 1)
     expect(c.value).toBe(1)
   })
+
+  test('should return true for reactive objects', () => {
+    expect(isReactive(reactive({}))).toBe(true)
+    expect(isReactive(readonly(reactive({})))).toBe(true)
+    expect(isReactive(ref({}).value)).toBe(true)
+    expect(isReactive(readonly(ref({})).value)).toBe(true)
+    expect(isReactive(shallowReactive({}))).toBe(true)
+  })
+
+  test('should return false for non-reactive objects', () => {
+    expect(isReactive(ref(true))).toBe(false)
+    expect(isReactive(shallowRef({}).value)).toBe(false)
+  })
 })