Skip to content

Commit

Permalink
fix(InstantSearch): throw error when init and render are not defined. F…
Browse files Browse the repository at this point in the history
…ixes #499
  • Loading branch information
maxiloc committed Nov 9, 2015
1 parent fbeff9b commit 2830cd3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Usage: instantsearch({

addWidget(widgetDefinition) {
// Add the widget to the list of widget
if (widgetDefinition.render === undefined && widgetDefinition.init === undefined) {
throw new Error('Widget definition missing render or init method');
}

this.widgets.push(widgetDefinition);
}

Expand Down
15 changes: 15 additions & 0 deletions lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ describe('InstantSearch lifecycle', () => {
expect(algoliasearchHelper.notCalled).toBe(true, 'algoliasearchHelper not yet called');
});

context('when adding a widget without render and init', () => {
let widget;

beforeEach(() => {
widget = {};
});

it('throw an error', function() {
expect(() => {
search.addWidget(widget);
}).toThrow('Widget definition missing render or init method');
});
});

context('when adding a widget', () => {
let widget;

Expand Down Expand Up @@ -148,6 +162,7 @@ describe('InstantSearch lifecycle', () => {
widgets = range(5);
widgets = widgets.map((widget, widgetIndex) => {
widget = {
init: function() {},
getConfiguration: sinon.stub().returns({values: [widgetIndex]})
};

Expand Down

0 comments on commit 2830cd3

Please sign in to comment.