Skip to content

Commit

Permalink
fix(menu): avoid error when no facet values are retrieved
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrutjes committed Mar 2, 2018
1 parent db113a4 commit 0dbb683
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export default {
this.sortBy
);
return data;
if (Array.isArray(data)) {
return data;
}
return [];
},
show() {
return this.facetValues.length > 0;
Expand Down
2 changes: 2 additions & 0 deletions src/components/__tests__/__snapshots__/menu.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ exports[`Menu should render correctly 1`] = `
</div>
`;

exports[`Menu should render nothing if no menu entries are available 1`] = `undefined`;
16 changes: 16 additions & 0 deletions src/components/__tests__/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ describe('Menu', () => {
expect(vm.$el.outerHTML).toMatchSnapshot();
});

it('should render nothing if no menu entries are available', () => {
const Component = Vue.extend(Menu);

const store = Object.assign({}, searchStore, {
getFacetValues: () => ({ data: null }),
});
const vm = new Component({
propsData: {
attribute: 'category',
searchStore: store,
},
});
vm.$mount();
expect(vm.$el.outerHTML).toMatchSnapshot();
});

it('should add a facet to the store when created', () => {
const Component = Vue.extend(Menu);
const addFacetMock = jest.fn();
Expand Down

0 comments on commit 0dbb683

Please sign in to comment.