File tree 2 files changed +37
-2
lines changed
2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,15 @@ export function clone<T>(
111
111
if ( ! descriptor )
112
112
continue
113
113
const cloned = clone ( ( val as any ) [ k ] , seen , options )
114
- if ( 'get' in descriptor ) {
114
+ if ( options . forceWritable ) {
115
+ Object . defineProperty ( out , k , {
116
+ enumerable : descriptor . enumerable ,
117
+ configurable : true ,
118
+ writable : true ,
119
+ value : cloned ,
120
+ } )
121
+ }
122
+ else if ( 'get' in descriptor ) {
115
123
Object . defineProperty ( out , k , {
116
124
...descriptor ,
117
125
get ( ) {
@@ -122,7 +130,6 @@ export function clone<T>(
122
130
else {
123
131
Object . defineProperty ( out , k , {
124
132
...descriptor ,
125
- writable : options . forceWritable ? true : descriptor . writable ,
126
133
value : cloned ,
127
134
} )
128
135
}
Original file line number Diff line number Diff line change @@ -115,6 +115,34 @@ test('asymmetric matcher in nested', () => {
115
115
` )
116
116
} )
117
117
118
+ test ( 'getter only property' , ( ) => {
119
+ setupColors ( getDefaultColors ( ) )
120
+ const x = { normalProp : 1 }
121
+ const y = { normalProp : 2 }
122
+ Object . defineProperty ( x , 'getOnlyProp' , {
123
+ enumerable : true ,
124
+ get : ( ) => ( { a : 'b' } ) ,
125
+ } )
126
+ Object . defineProperty ( y , 'getOnlyProp' , {
127
+ enumerable : true ,
128
+ get : ( ) => ( { a : 'b' } ) ,
129
+ } )
130
+ expect (
131
+ getErrorDiff ( x , y ) ,
132
+ ) . toMatchInlineSnapshot ( `
133
+ "- Expected
134
+ + Received
135
+
136
+ Object {
137
+ "getOnlyProp": Object {
138
+ "a": "b",
139
+ },
140
+ - "normalProp": 2,
141
+ + "normalProp": 1,
142
+ }"
143
+ ` )
144
+ } )
145
+
118
146
function getErrorDiff ( actual : unknown , expected : unknown ) {
119
147
try {
120
148
expect ( actual ) . toEqual ( expected )
You can’t perform that action at this time.
0 commit comments