Skip to content

Commit

Permalink
fix(suggestions) handle null data (#144)
Browse files Browse the repository at this point in the history
Fixes #124
  • Loading branch information
darrenjennings authored Sep 11, 2019
1 parent 5b00418 commit a3ea362
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions __tests__/__snapshots__/autosuggest.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ exports[`Autosuggest can display section header 1`] = `
</div>
`;
exports[`Autosuggest can handle null data 1`] = `
<div id="autosuggest"><input type="text" autocomplete="off" role="combobox" aria-autocomplete="list" aria-owns="autosuggest__results" aria-activedescendant="" aria-haspopup="false" aria-expanded="false" id="autosuggest__input" placeholder="Type 'G'">
<div class="autosuggest__results-container">
<!---->
</div>
</div>
`;
exports[`Autosuggest can modify input type attribute 1`] = `
<div id="autosuggest"><input type="search" autocomplete="off" role="combobox" aria-autocomplete="list" aria-owns="autosuggest__results" aria-activedescendant="" aria-haspopup="false" aria-expanded="false" id="autosuggest__input" placeholder="Type 'G'">
<div class="autosuggest__results-container">
Expand Down
14 changes: 14 additions & 0 deletions __tests__/autosuggest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,4 +703,18 @@ describe("Autosuggest", () => {
wrapper.setData({ ph: 'Please type here...' })
expect(input.attributes("placeholder")).toBe('Please type here...')
});

it("can handle null data", async () => {
const props = {...defaultProps, suggestions: [{ data: null }]};

const wrapper = shallowMount(Autosuggest, {
propsData: props
});

const renderer = createRenderer();
renderer.renderToString(wrapper.vm, (err, str) => {
if (err) throw new Error(err);
expect(str).toMatchSnapshot();
});
});
});
1 change: 1 addition & 0 deletions src/Autosuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export default {
// For each section, make sure we calculate the size
// based on how many are rendered, which maxes out at
// the limit but can be less than the limit.
if (!section) return acc
const { limit, data } = section
return acc + (data.length >= limit ? limit : data.length)
}, 0)
Expand Down

0 comments on commit a3ea362

Please sign in to comment.