@@ -3,7 +3,7 @@ import { createSchema, number, string, table, Zero } from '@rocicorp/zero'
33import { describe , expect , it , vi } from 'vitest'
44import { ref , watchEffect } from 'vue'
55import { useQuery } from './query'
6- import { vueViewFactory } from './view'
6+ import { VueView , vueViewFactory } from './view'
77
88async function setupTestEnvironment ( ) {
99 const schema = createSchema ( {
@@ -80,8 +80,12 @@ describe('useQuery', () => {
8080 z . close ( )
8181 } )
8282
83- it ( 'useQuery with ttl' , async ( ) => {
83+ it ( 'useQuery with ttl (zero@0.18) ' , async ( ) => {
8484 const { z, tableQuery } = await setupTestEnvironment ( )
85+ if ( ! ( 'updateTTL' in tableQuery ) ) {
86+ // 0.19 removed updateTTL from the query
87+ return
88+ }
8589 const ttl = ref < TTL > ( '1m' )
8690
8791 const materializeSpy = vi . spyOn ( tableQuery , 'materialize' )
@@ -107,6 +111,40 @@ describe('useQuery', () => {
107111 z . close ( )
108112 } )
109113
114+ it ( 'useQuery with ttl (zero@0.19)' , async ( ) => {
115+ const { z, tableQuery } = await setupTestEnvironment ( )
116+ if ( 'updateTTL' in tableQuery ) {
117+ // 0.19 removed updateTTL from the query
118+ return
119+ }
120+
121+ const ttl = ref < TTL > ( '1m' )
122+
123+ const materializeSpy = vi . spyOn ( tableQuery , 'materialize' )
124+
125+ const queryGetter = vi . fn ( ( ) => tableQuery )
126+
127+ useQuery ( queryGetter , ( ) => ( { ttl : ttl . value } ) )
128+ expect ( queryGetter ) . toHaveBeenCalledTimes ( 1 )
129+ expect ( materializeSpy ) . toHaveBeenCalledExactlyOnceWith (
130+ vueViewFactory ,
131+ '1m' ,
132+ )
133+ expect ( materializeSpy ) . toHaveLastReturnedWith ( expect . any ( VueView ) )
134+ const view : VueView < unknown > = materializeSpy . mock . results [ 0 ] ! . value
135+ const updateTTLSpy = vi . spyOn ( view , 'updateTTL' )
136+
137+ materializeSpy . mockClear ( )
138+
139+ ttl . value = '10m'
140+ await 1
141+
142+ expect ( materializeSpy ) . toHaveBeenCalledTimes ( 0 )
143+ expect ( updateTTLSpy ) . toHaveBeenCalledExactlyOnceWith ( '10m' )
144+
145+ z . close ( )
146+ } )
147+
110148 it ( 'useQuery deps change' , async ( ) => {
111149 const { z, tableQuery } = await setupTestEnvironment ( )
112150
0 commit comments