File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -476,7 +476,7 @@ describe('reactivity/readonly', () => {
476
476
expect ( isReadonly ( rr . foo ) ) . toBe ( true )
477
477
} )
478
478
479
- test ( 'attemptingt to write to a readonly ref nested in a reactive object should fail' , ( ) => {
479
+ test ( 'attemptingt to write plain value to a readonly ref nested in a reactive object should fail' , ( ) => {
480
480
const r = ref ( false )
481
481
const ror = readonly ( r )
482
482
const obj = reactive ( { ror } )
@@ -486,4 +486,15 @@ describe('reactivity/readonly', () => {
486
486
487
487
expect ( obj . ror ) . toBe ( false )
488
488
} )
489
+ test ( 'replacing a readonly ref nested in a reactive object with a new ref' , ( ) => {
490
+ const r = ref ( false )
491
+ const ror = readonly ( r )
492
+ const obj = reactive ( { ror } )
493
+ try {
494
+ obj . ror = ref ( true ) as unknown as boolean
495
+ } catch ( e ) { }
496
+
497
+ expect ( obj . ror ) . toBe ( true )
498
+ expect ( toRaw ( obj ) . ror ) . not . toBe ( ror ) // ref successfully replaced
499
+ } )
489
500
} )
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ function createSetter(shallow = false) {
150
150
receiver : object
151
151
) : boolean {
152
152
let oldValue = ( target as any ) [ key ]
153
- if ( isReadonly ( oldValue ) && isRef ( oldValue ) ) {
153
+ if ( isReadonly ( oldValue ) && isRef ( oldValue ) && ! isRef ( value ) ) {
154
154
return false
155
155
}
156
156
if ( ! shallow && ! isReadonly ( value ) ) {
You can’t perform that action at this time.
0 commit comments