77 watch ,
88 nextTick ,
99 readonly ,
10+ isReadonly ,
11+ toRaw ,
12+ computed ,
1013} from '../../../src'
1114
1215const Vue = require ( 'vue/dist/vue.common.js' )
@@ -292,21 +295,21 @@ describe('reactivity/readonly', () => {
292295 // })
293296 // })
294297
295- // test('calling reactive on an readonly should return readonly', () => {
296- // const a = readonly({})
297- // const b = reactive(a)
298- // expect(isReadonly(b)).toBe(true)
299- // // should point to same original
300- // expect(toRaw(a)).toBe(toRaw(b))
301- // })
298+ test ( 'calling reactive on an readonly should return readonly' , ( ) => {
299+ const a = readonly ( { } )
300+ const b = reactive ( a )
301+ expect ( isReadonly ( b ) ) . toBe ( true )
302+ // should point to same original
303+ expect ( toRaw ( a ) ) . toBe ( toRaw ( b ) )
304+ } )
302305
303- // test('calling readonly on a reactive object should return readonly', () => {
304- // const a = reactive({})
305- // const b = readonly(a)
306- // expect(isReadonly(b)).toBe(true)
307- // // should point to same original
308- // expect(toRaw(a)).toBe(toRaw(b))
309- // })
306+ test ( 'calling readonly on a reactive object should return readonly' , ( ) => {
307+ const a = reactive ( { } )
308+ const b = readonly ( a )
309+ expect ( isReadonly ( b ) ) . toBe ( true )
310+ // should point to same original
311+ expect ( toRaw ( a ) ) . toBe ( toRaw ( b ) )
312+ } )
310313
311314 // test('readonly should track and trigger if wrapping reactive original', () => {
312315 // const a = reactive({ n: 1 })
@@ -324,19 +327,19 @@ describe('reactivity/readonly', () => {
324327 // expect(dummy).toBe(2)
325328 // })
326329
327- // test('wrapping already wrapped value should return same Proxy', () => {
328- // const original = { foo: 1 }
329- // const wrapped = readonly(original)
330- // const wrapped2 = readonly(wrapped)
331- // expect(wrapped2).toBe(wrapped)
332- // })
330+ test ( 'wrapping already wrapped value should return same Proxy' , ( ) => {
331+ const original = { foo : 1 }
332+ const wrapped = readonly ( original )
333+ const wrapped2 = readonly ( wrapped )
334+ expect ( wrapped2 ) . toBe ( wrapped )
335+ } )
333336
334- // test('wrapping the same value multiple times should return same Proxy', () => {
335- // const original = { foo: 1 }
336- // const wrapped = readonly(original)
337- // const wrapped2 = readonly(original)
338- // expect(wrapped2).toBe(wrapped)
339- // })
337+ test ( 'wrapping the same value multiple times should return same Proxy' , ( ) => {
338+ const original = { foo : 1 }
339+ const wrapped = readonly ( original )
340+ const wrapped2 = readonly ( original )
341+ expect ( wrapped2 ) . toBe ( wrapped )
342+ } )
340343
341344 // test('markRaw', () => {
342345 // const obj = readonly({
@@ -474,5 +477,22 @@ describe('reactivity/readonly', () => {
474477 ) . toHaveBeenWarned ( )
475478 expect ( vm . $el . textContent ) . toBe ( `1` )
476479 } )
480+
481+ it ( 'should mark computed as readonly' , ( ) => {
482+ expect ( isReadonly ( computed ( ( ) => { } ) ) ) . toBe ( true )
483+ expect (
484+ isReadonly (
485+ computed ( {
486+ get : ( ) => { } ,
487+ set : ( ) => { } ,
488+ } )
489+ )
490+ ) . toBe ( false )
491+ } )
492+
493+ // #811
494+ it ( 'should not mark ref as readonly' , ( ) => {
495+ expect ( isReadonly ( ref ( [ ] ) ) ) . toBe ( false )
496+ } )
477497 } )
478498} )
0 commit comments