@@ -6,45 +6,52 @@ const MockReactInstantSearch = jest.genMockFromModule(
6
6
'react-instantsearch-dom' ,
7
7
) ;
8
8
9
- let fakeHits = [
10
- {
11
- objectID : '1' ,
12
- title : 'bla' ,
13
- key : 'Bees101' ,
14
- type : 'course' ,
15
- aggregation_key : 'course:Bees101' ,
16
- authoring_organizations : [ ] ,
17
- card_image_url : 'https://fake.image' ,
18
- course_keys : [ ] ,
19
- } ,
20
- {
21
- objectID : '2' ,
22
- title : 'blp' ,
23
- key : 'Wasps200' ,
24
- type : 'course' ,
25
- aggregation_key : 'course:Wasps200' ,
26
- authoring_organizations : [ ] ,
27
- card_image_url : 'https://fake.image' ,
28
- course_keys : [ ] ,
29
- } ,
30
- ] ;
9
+ let mockState = {
10
+ hits : [
11
+ {
12
+ objectID : '1' ,
13
+ title : 'bla' ,
14
+ key : 'Bees101' ,
15
+ type : 'course' ,
16
+ aggregation_key : 'course:Bees101' ,
17
+ authoring_organizations : [ ] ,
18
+ card_image_url : 'https://fake.image' ,
19
+ course_keys : [ ] ,
20
+ } ,
21
+ {
22
+ objectID : '2' ,
23
+ title : 'blp' ,
24
+ key : 'Wasps200' ,
25
+ type : 'course' ,
26
+ aggregation_key : 'course:Wasps200' ,
27
+ authoring_organizations : [ ] ,
28
+ card_image_url : 'https://fake.image' ,
29
+ course_keys : [ ] ,
30
+ } ,
31
+ ] ,
32
+ nbHits : 2 ,
33
+ } ;
31
34
32
35
// This allows you to override the built-in hits object
33
36
const setFakeHits = hits => {
34
- fakeHits = hits ;
37
+ mockState . hits = hits ;
38
+ mockState . nbHits = hits . length ;
35
39
} ;
36
40
37
- MockReactInstantSearch . configure = {
38
- nbHits : 2 ,
41
+ const resetMockReactInstantSearch = ( ) => {
42
+ mockState = {
43
+ hits : [ ...mockState . hits ] , // deep clone if needed
44
+ nbHits : 2 ,
45
+ } ;
39
46
} ;
40
47
41
48
MockReactInstantSearch . connectStateResults = Component => ( props ) => (
42
49
< Component
43
50
searchResults = { {
44
- hits : MockReactInstantSearch . configure . nbHits === 0 ? [ ] : fakeHits ,
51
+ hits : mockState . hits ,
45
52
hitsPerPage : 25 ,
46
- nbHits : MockReactInstantSearch . configure . nbHits ,
47
- nbPages : MockReactInstantSearch . configure . nbHits === 0 ? 0 : 1 ,
53
+ nbHits : mockState . nbHits ,
54
+ nbPages : mockState . nbHits === 0 ? 0 : 1 ,
48
55
page : 1 ,
49
56
} }
50
57
isSearchStalled = { false }
@@ -57,7 +64,7 @@ MockReactInstantSearch.connectStateResults = Component => (props) => (
57
64
58
65
MockReactInstantSearch . connectPagination = Component => ( props ) => (
59
66
< Component
60
- nbPages = { MockReactInstantSearch . configure . nbHits === 0 ? 0 : 1 }
67
+ nbPages = { mockState . nbHits === 0 ? 0 : 1 }
61
68
currentRefinement = { 1 }
62
69
maxPagesDisplayed = { 5 }
63
70
{ ...props }
@@ -84,4 +91,5 @@ MockReactInstantSearch.Index = function Index({ children }) { return children; }
84
91
module . exports = {
85
92
...MockReactInstantSearch ,
86
93
setFakeHits,
94
+ resetMockReactInstantSearch,
87
95
} ;
0 commit comments