File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed
Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -141,9 +141,11 @@ function mockObserver(value: any = {}): any {
141141
142142export function shallowReactive < T extends object = any > ( obj : T ) : T
143143export function shallowReactive ( obj : any ) : any {
144- if ( __DEV__ && ! obj ) {
145- warn ( '"shallowReactive()" is called without provide an "object".' )
146- return
144+ if ( ! isObject ( obj ) ) {
145+ if ( __DEV__ ) {
146+ warn ( '"shallowReactive()" is called without provide an "object".' )
147+ }
148+ return obj as any
147149 }
148150
149151 if (
Original file line number Diff line number Diff line change @@ -207,4 +207,34 @@ describe('reactivity/reactive', () => {
207207 expect ( isReactive ( props . n ) ) . toBe ( true )
208208 } )
209209 } )
210+
211+ test ( 'should shallowReactive non-observable values' , ( ) => {
212+ const assertValue = ( value : any ) => {
213+ expect ( shallowReactive ( value ) ) . toBe ( value )
214+ }
215+
216+ // number
217+ assertValue ( 1 )
218+ // string
219+ assertValue ( 'foo' )
220+ // boolean
221+ assertValue ( false )
222+ // null
223+ assertValue ( null )
224+ // undefined
225+ assertValue ( undefined )
226+ // symbol
227+ const s = Symbol ( )
228+ assertValue ( s )
229+
230+ expect ( warn ) . toBeCalledTimes ( 6 )
231+ expect (
232+ warn . mock . calls . map ( ( call ) => {
233+ expect ( call [ 0 ] ) . toBe (
234+ '[Vue warn]: "shallowReactive()" is called without provide an "object".'
235+ )
236+ } )
237+ )
238+ warn . mockReset ( )
239+ } )
210240} )
You can’t perform that action at this time.
0 commit comments