|
|
@@ -1,5 +1,14 @@
|
|
|
-import { shallowReadonly } from '@vue/reactivity'
|
|
|
-import { ref, readonly, describe, expectError, expectType, Ref } from './index'
|
|
|
+import {
|
|
|
+ ref,
|
|
|
+ readonly,
|
|
|
+ shallowReadonly,
|
|
|
+ describe,
|
|
|
+ expectError,
|
|
|
+ expectType,
|
|
|
+ Ref,
|
|
|
+ reactive,
|
|
|
+ markRaw
|
|
|
+} from './index'
|
|
|
|
|
|
describe('should support DeepReadonly', () => {
|
|
|
const r = readonly({ obj: { k: 'v' } })
|
|
|
@@ -15,6 +24,35 @@ describe('readonly ref', () => {
|
|
|
expectType<Ref>(r)
|
|
|
})
|
|
|
|
|
|
+describe('should support markRaw', () => {
|
|
|
+ class Test<T> {
|
|
|
+ item = {} as Ref<T>
|
|
|
+ }
|
|
|
+ const test = new Test<number>()
|
|
|
+ const plain = {
|
|
|
+ ref: ref(1)
|
|
|
+ }
|
|
|
+
|
|
|
+ const r = reactive({
|
|
|
+ class: {
|
|
|
+ raw: markRaw(test),
|
|
|
+ reactive: test
|
|
|
+ },
|
|
|
+ plain: {
|
|
|
+ raw: markRaw(plain),
|
|
|
+ reactive: plain
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ expectType<Test<number>>(r.class.raw)
|
|
|
+ // @ts-expect-error it should unwrap
|
|
|
+ expectType<Test<number>>(r.class.reactive)
|
|
|
+
|
|
|
+ expectType<Ref<number>>(r.plain.raw.ref)
|
|
|
+ // @ts-expect-error it should unwrap
|
|
|
+ expectType<Ref<number>>(r.plain.reactive.ref)
|
|
|
+})
|
|
|
+
|
|
|
describe('shallowReadonly ref unwrap', () => {
|
|
|
const r = shallowReadonly({ count: { n: ref(1) } })
|
|
|
// @ts-expect-error
|