@@ -18,6 +18,7 @@ import Vuex from 'vuex'
18
18
import { mount , shallowMount } from '@vue/test-utils'
19
19
import InstrumentComponent from './InstrumentComponent'
20
20
import { computed , isRef } from '@vue/composition-api'
21
+ import { HookContext } from '@feathersjs/feathers'
21
22
jsdom ( )
22
23
require ( 'events' ) . EventEmitter . prototype . _maxListeners = 100
23
24
@@ -151,4 +152,42 @@ describe('use/get', function() {
151
152
152
153
assert ( hasBeenRequested . value === false , 'no request after get' )
153
154
} )
155
+
156
+ it ( 'API only hit once on initial render' , async function ( ) {
157
+ const { makeServicePlugin, BaseModel } = feathersVuex ( feathersClient , {
158
+ serverAlias : 'useGet'
159
+ } )
160
+
161
+ class Dohickey extends BaseModel {
162
+ public static modelName = 'Dohickey'
163
+ }
164
+
165
+ const servicePath = 'dohickies'
166
+ const store = new Vuex . Store ( {
167
+ plugins : [
168
+ makeServicePlugin ( {
169
+ Model : Dohickey ,
170
+ servicePath,
171
+ service : feathersClient . service ( servicePath )
172
+ } )
173
+ ]
174
+ } )
175
+
176
+ let getCalls = 0
177
+ feathersClient . service ( servicePath ) . hooks ( {
178
+ before : {
179
+ get : [
180
+ ( ctx : HookContext ) => {
181
+ getCalls += 1
182
+ ctx . result = { id : ctx . id }
183
+ }
184
+ ]
185
+ }
186
+ } )
187
+
188
+ useGet ( { model : Dohickey , id : 42 } )
189
+ await new Promise ( resolve => setTimeout ( resolve , 100 ) )
190
+
191
+ assert ( getCalls === 1 , '`get` called once' )
192
+ } )
154
193
} )
0 commit comments