Skip to content

Commit 9cd715c

Browse files
committed
new: add test to verify get is only called once
1 parent 0507f97 commit 9cd715c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/use/get.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Vuex from 'vuex'
1818
import { mount, shallowMount } from '@vue/test-utils'
1919
import InstrumentComponent from './InstrumentComponent'
2020
import { computed, isRef } from '@vue/composition-api'
21+
import { HookContext } from '@feathersjs/feathers'
2122
jsdom()
2223
require('events').EventEmitter.prototype._maxListeners = 100
2324

@@ -151,4 +152,42 @@ describe('use/get', function() {
151152

152153
assert(hasBeenRequested.value === false, 'no request after get')
153154
})
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+
})
154193
})

0 commit comments

Comments
 (0)