11import { describe , beforeEach , it , expect , vi } from 'vitest'
2- import { computed , markRaw , reactive , ref , ToRefs } from 'vue'
2+ import { computed , reactive , ref , ToRefs } from 'vue'
33import { createPinia , defineStore , setActivePinia , storeToRefs } from '../src'
44import { mockWarn } from './vitest-mock-warn'
55
@@ -203,7 +203,7 @@ describe('storeToRefs', () => {
203203 expect ( spy ) . toHaveBeenCalledTimes ( 0 )
204204 } )
205205
206- it ( 'does not crash and warns on a non-reactive null value' , ( ) => {
206+ it ( 'does not crash on a non-reactive null value' , ( ) => {
207207 const useStore = defineStore ( 'null-val' , ( ) => {
208208 return {
209209 nullableItem : null as null | { id : number } ,
@@ -217,52 +217,8 @@ describe('storeToRefs', () => {
217217 expect ( refs ) . toHaveProperty ( 'text' )
218218 expect ( refs ) . not . toHaveProperty ( 'nullableItem' )
219219 expect ( refs . text . value ) . toBe ( 'hello' )
220- expect ( '"nullableItem"' ) . toHaveBeenWarned ( )
221- expect ( 'is not reactive' ) . toHaveBeenWarned ( )
222- } )
223-
224- it ( 'warns on a non-reactive plain object value' , ( ) => {
225- const useStore = defineStore ( 'plain-obj' , ( ) => {
226- return { config : { dark : true } , textRef : ref ( 'hi' ) }
227- } )
228-
229- storeToRefs ( useStore ( ) )
230- expect ( '"config"' ) . toHaveBeenWarned ( )
231- expect ( '"textRef"' ) . not . toHaveBeenWarned ( )
232- } )
233-
234- it ( 'does not warn on markRaw non-reactive properties' , ( ) => {
235- const useStore = defineStore ( 'raw-prop' , ( ) => {
236- return { external : markRaw ( { dark : true } ) , text : ref ( 'hi' ) }
237- } )
238-
239- const refs = storeToRefs ( useStore ( ) )
240- expect ( refs ) . not . toHaveProperty ( 'external' )
241- expect ( refs ) . toHaveProperty ( 'text' )
242- } )
243-
244- it ( 'warns on a non-reactive property added by a plugin' , ( ) => {
245- const pinia = createPinia ( )
246- // directly push because no app
247- pinia . _p . push ( ( ) => // @ts -expect-error: invalid state
248- ( { external : { dark : true } } ) )
249- setActivePinia ( pinia )
250-
251- const refs = storeToRefs ( defineStore ( 'a' , ( ) => ( { n : ref ( 0 ) } ) ) ( ) )
252- expect ( refs ) . not . toHaveProperty ( 'external' )
253- expect ( '"external"' ) . toHaveBeenWarned ( )
254- } )
255-
256- it ( 'does not warn on a markRaw property added by a plugin' , ( ) => {
257- const pinia = createPinia ( )
258- pinia . _p . push ( ( ) => ( { external : markRaw ( { dark : true } ) , shared : 10 } ) )
259- setActivePinia ( pinia )
260-
261- const refs = storeToRefs ( defineStore ( 'a' , ( ) => ( { n : ref ( 0 ) } ) ) ( ) )
262- expect ( refs ) . not . toHaveProperty ( 'external' )
263- // primitives are skipped silently too
264- expect ( refs ) . not . toHaveProperty ( 'shared' )
265- expect ( refs ) . toHaveProperty ( 'n' )
220+ // mockWarn() asserts storeToRefs() stays silent: the warning is emitted when
221+ // the property is added by a plugin, not here
266222 } )
267223
268224 tds ( ( ) => {
0 commit comments