7
7
watch ,
8
8
nextTick ,
9
9
readonly ,
10
+ isReadonly ,
11
+ toRaw ,
12
+ computed ,
10
13
} from '../../../src'
11
14
12
15
const Vue = require ( 'vue/dist/vue.common.js' )
@@ -292,21 +295,21 @@ describe('reactivity/readonly', () => {
292
295
// })
293
296
// })
294
297
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
+ } )
302
305
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
+ } )
310
313
311
314
// test('readonly should track and trigger if wrapping reactive original', () => {
312
315
// const a = reactive({ n: 1 })
@@ -324,19 +327,19 @@ describe('reactivity/readonly', () => {
324
327
// expect(dummy).toBe(2)
325
328
// })
326
329
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
+ } )
333
336
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
+ } )
340
343
341
344
// test('markRaw', () => {
342
345
// const obj = readonly({
@@ -474,5 +477,22 @@ describe('reactivity/readonly', () => {
474
477
) . toHaveBeenWarned ( )
475
478
expect ( vm . $el . textContent ) . toBe ( `1` )
476
479
} )
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
+ } )
477
497
} )
478
498
} )
0 commit comments