Skip to content

Commit dc9371c

Browse files
committed
fix(hitsPerPageSelector): Issue when state did not have a hitsPerPage
1 parent 35306d5 commit dc9371c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ describe('hitsPerPageSelector()', () => {
102102
}).toThrow(/No option in `options` with `value: -1`/);
103103
});
104104

105+
it('should not throw an error if state does not have a `hitsPerPage`', () => {
106+
delete helper.state.hitsPerPage;
107+
expect(() => {
108+
widget.init(helper.state, helper);
109+
}).toNotThrow(/No option in `options`/);
110+
});
111+
105112
afterEach(() => {
106113
hitsPerPageSelector.__ResetDependency__('ReactDOM');
107114
hitsPerPageSelector.__ResetDependency__('autoHideContainer');

widgets/hits-per-page-selector/hits-per-page-selector.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ function hitsPerPageSelector({
4141
return {
4242
init: function(state) {
4343
let isCurrentInOptions = reduce(options, function(res, option) {
44+
if (state.hitsPerPage === undefined) {
45+
return true;
46+
}
4447
return res || +state.hitsPerPage === +option.value;
4548
}, false);
49+
4650
if (!isCurrentInOptions) {
4751
throw new Error('[hitsPerPageSelector]: No option in `options` with `value: ' + state.hitsPerPage + '`');
4852
}

0 commit comments

Comments
 (0)