diff --git a/__tests__/__snapshots__/autosuggest.test.js.snap b/__tests__/__snapshots__/autosuggest.test.js.snap index eb752d6..9366a87 100644 --- a/__tests__/__snapshots__/autosuggest.test.js.snap +++ b/__tests__/__snapshots__/autosuggest.test.js.snap @@ -51,6 +51,14 @@ exports[`Autosuggest can display section header 1`] = ` `; +exports[`Autosuggest can handle null data 1`] = ` +
+
+ +
+
+`; + exports[`Autosuggest can modify input type attribute 1`] = `
diff --git a/__tests__/autosuggest.test.js b/__tests__/autosuggest.test.js index 10f3ce8..f3c87a9 100644 --- a/__tests__/autosuggest.test.js +++ b/__tests__/autosuggest.test.js @@ -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(); + }); + }); }); diff --git a/src/Autosuggest.vue b/src/Autosuggest.vue index 650e161..b613c60 100644 --- a/src/Autosuggest.vue +++ b/src/Autosuggest.vue @@ -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)