Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(highlight): gracefully display empty string if attr is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrutjes committed Apr 10, 2017
1 parent 06e7c1f commit 3976dca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vue-instantsearch-highlight/src/Highlight.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
const attributeName = ctx.props.attributeName
const tagName = ctx.props.tagName
if (!result._highlightResult || !result._highlightResult[attributeName]) {
throw new Error(`Attribute ${attributeName} is not highlighted.`)
}
let attributeValue = ''
if (result._highlightResult && result._highlightResult[attributeName]) {
attributeValue = result._highlightResult[attributeName].value
}
let attributeValue = result._highlightResult[attributeName].value
if (ctx.props.escapeHtml === true) {
attributeValue = escapeHtml(attributeValue)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ exports[`renders proper HTML 1`] = `
<span class="ais-highlight">con
<mark>ten</mark>t</span>
`;

exports[`should render an empty string if attribute is not highlighted 1`] = `<span class="ais-highlight"></span>`;
24 changes: 24 additions & 0 deletions packages/vue-instantsearch-highlight/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,29 @@ test('allows unsafe output', () => {
}
}).$mount();

expect(vm.$el.outerHTML).toMatchSnapshot();
});

test('should render an empty string if attribute is not highlighted', () => {
const result = {
_highlightResult: {}
};

const vm = new Vue({
template: '<highlight attributeName="attr" :result="result">',
render(h) {
return h('highlight', {
props: {
attributeName: 'attr',
result: result
}
});
},
components: {
Highlight
}
}).$mount();


expect(vm.$el.outerHTML).toMatchSnapshot();
});

0 comments on commit 3976dca

Please sign in to comment.