Skip to content

Commit 93d8432

Browse files
fix(hitsPerPage): improve warning for missing state value (#3707)
* fix(hitsPerPage): improve warning for missing state value I stumbled across this development warning message and couldn't understand it. I tried to rephrase it. * fix(stories): add state value in hitsPerPage The stories display 4 hits so we need to add another entry with the value `4` if we don't use the `default` attribute.
1 parent 55d4c0d commit 93d8432

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/connectors/hits-per-page/connectHitsPerPage.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,12 @@ Learn more: https://community.algolia.com/instantsearch.js/v2/widgets/configure.
143143

144144
warning(
145145
false,
146-
`No items in HitsPerPage \`items\` with \`value: hitsPerPage\` (hitsPerPage: ${
146+
`
147+
The \`items\` option of \`hitsPerPage\` does not contain the "hits per page" value coming from the state: ${
147148
state.hitsPerPage
148-
})`
149+
}.
150+
151+
You may want to add another entry to the \`items\` option with this value.`
149152
);
150153

151154
items = [{ value: '', label: '' }, ...items];

src/widgets/hits-per-page/__tests__/hits-per-page-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ describe('hitsPerPage()', () => {
121121
expect(() => {
122122
widget.init({ state: helper.state, helper });
123123
}).toWarnDev(
124-
'[InstantSearch.js]: No items in HitsPerPage `items` with `value: hitsPerPage` (hitsPerPage: 20)'
124+
`[InstantSearch.js]: The \`items\` option of \`hitsPerPage\` does not contain the "hits per page" value coming from the state: 20.
125+
126+
You may want to add another entry to the \`items\` option with this value.`
125127
);
126128
});
127129

@@ -131,7 +133,9 @@ describe('hitsPerPage()', () => {
131133
expect(() => {
132134
widget.init({ state: helper.state, helper });
133135
}).toWarnDev(
134-
'[InstantSearch.js]: No items in HitsPerPage `items` with `value: hitsPerPage` (hitsPerPage: -1)'
136+
`[InstantSearch.js]: The \`items\` option of \`hitsPerPage\` does not contain the "hits per page" value coming from the state: -1.
137+
138+
You may want to add another entry to the \`items\` option with this value.`
135139
);
136140
});
137141

stories/hits-per-page.stories.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ storiesOf('HitsPerPage', module)
1010
container,
1111
items: [
1212
{ value: 3, label: '3 per page' },
13+
{ value: 4, label: '4 per page' },
1314
{ value: 5, label: '5 per page' },
1415
{ value: 10, label: '10 per page' },
1516
],
@@ -39,7 +40,7 @@ storiesOf('HitsPerPage', module)
3940
instantsearch.widgets.hitsPerPage({
4041
container,
4142
items: [
42-
{ value: 3, label: '3 per page' },
43+
{ value: 3, label: '3 per page', default: true },
4344
{ value: 5, label: '5 per page' },
4445
{ value: 10, label: '10 per page' },
4546
],

0 commit comments

Comments
 (0)