@@ -6,23 +6,32 @@ import InstantSearch from '../InstantSearch.vue';
6
6
jest . mock ( 'instantsearch.js/es' , ( ) => {
7
7
const isPlainObject = require ( 'lodash/isPlainObject' ) ;
8
8
const start = jest . fn ( ) ;
9
+
10
+ class RoutingManager {
11
+ constructor ( routing ) {
12
+ this . _routing = routing ;
13
+ }
14
+ }
9
15
const fakeInstantSearch = jest . fn (
10
16
( {
11
17
indexName,
12
18
searchClient,
13
- routing, // eslint-disable-line no-unused-vars
14
- stalledSearchDelay, // eslint-disable-line no-unused-vars
15
- searchFunction, // eslint-disable-line no-unused-vars
19
+ routing,
20
+ stalledSearchDelay,
21
+ searchFunction,
16
22
} ) => {
17
- if ( ! searchClient && isPlainObject ( searchClient ) ) {
18
- throw new Error ( 'need searchClient to be a fn ' ) ;
23
+ if ( ! searchClient && ! isPlainObject ( searchClient ) ) {
24
+ throw new Error ( 'need searchClient to be a plain object ' ) ;
19
25
}
20
26
if ( ! indexName ) {
21
27
throw new Error ( 'need indexName to be a string' ) ;
22
28
}
23
29
return {
24
- start,
30
+ _stalledSearchDelay : stalledSearchDelay ,
31
+ _searchFunction : searchFunction ,
32
+ routing : new RoutingManager ( routing ) ,
25
33
helper : fakeInstantSearch . __helper ,
34
+ start,
26
35
} ;
27
36
}
28
37
) ;
@@ -191,26 +200,44 @@ it('Allows a change in `search-client`', () => {
191
200
expect ( instantsearch . __helper . search ) . toHaveBeenCalledTimes ( 1 ) ;
192
201
} ) ;
193
202
194
- it ( 'Does not allow a change in `search-function`' , ( ) => {
195
- global . console . error = jest . fn ( ) ;
203
+ it ( 'Allows a change in `search-function`' , ( ) => {
204
+ const oldValue = ( ) => { } ;
205
+ const newValue = ( ) => { } ;
206
+
196
207
const wrapper = mount ( InstantSearch , {
197
208
propsData : {
198
209
searchClient : { } ,
199
210
indexName : 'bla' ,
200
- searchFunction : ( ) => { } ,
211
+ searchFunction : oldValue ,
201
212
} ,
202
213
} ) ;
203
214
215
+ expect ( wrapper . vm . instantSearchInstance . _searchFunction ) . toEqual ( oldValue ) ;
216
+
204
217
wrapper . setProps ( {
205
- searchFunction : ( ) => { } ,
218
+ searchFunction : newValue ,
206
219
} ) ;
207
220
208
- // Vue catches this error and throws it to the console
209
- expect ( global . console . error . mock . calls [ 0 ] [ 0 ] ) . toMatchInlineSnapshot ( `
210
- [Error: searchFunction configuration can not be changed dynamically at this point.
221
+ expect ( wrapper . vm . instantSearchInstance . _searchFunction ) . toEqual ( newValue ) ;
222
+ } ) ;
211
223
212
- Please open a new issue: https://github.com/algolia/vue-instantsearch/issues/new?template=feature.md]
213
- ` ) ;
224
+ it ( 'Allows a change in `stalled-search-delay`' , ( ) => {
225
+ const wrapper = mount ( InstantSearch , {
226
+ propsData : {
227
+ searchClient : { } ,
228
+ indexName : 'bla' ,
229
+ searchFunction : ( ) => { } ,
230
+ stalledSearchDelay : 200 ,
231
+ } ,
232
+ } ) ;
233
+
234
+ expect ( wrapper . vm . instantSearchInstance . _stalledSearchDelay ) . toEqual ( 200 ) ;
235
+
236
+ wrapper . setProps ( {
237
+ stalledSearchDelay : 50 ,
238
+ } ) ;
239
+
240
+ expect ( wrapper . vm . instantSearchInstance . _stalledSearchDelay ) . toEqual ( 50 ) ;
214
241
} ) ;
215
242
216
243
it ( 'Does not allow a change in `routing`' , ( ) => {
0 commit comments