This repository was archived by the owner on Dec 30, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
packages/vue-instantsearch-highlight/src Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 2727 const attributeName = ctx .props .attributeName
2828 const tagName = ctx .props .tagName
2929
30- if (! result ._highlightResult || ! result ._highlightResult [attributeName]) {
31- throw new Error (` Attribute ${ attributeName} is not highlighted.` )
32- }
30+ let attributeValue = ' '
31+ if (result ._highlightResult && result ._highlightResult [attributeName]) {
32+ attributeValue = result ._highlightResult [attributeName].value
33+ }
3334
34- let attributeValue = result ._highlightResult [attributeName].value
3535 if (ctx .props .escapeHtml === true ) {
3636 attributeValue = escapeHtml (attributeValue)
3737 }
Original file line number Diff line number Diff line change @@ -17,3 +17,5 @@ exports[`renders proper HTML 1`] = `
1717<span class = " ais-highlight" >con
1818 <mark >ten</mark >t</span >
1919` ;
20+
21+ exports [` should render an empty string if attribute is not highlighted 1` ] = ` <span class = " ais-highlight" ></span >` ;
Original file line number Diff line number Diff line change @@ -109,5 +109,29 @@ test('allows unsafe output', () => {
109109 }
110110 } ) . $mount ( ) ;
111111
112+ expect ( vm . $el . outerHTML ) . toMatchSnapshot ( ) ;
113+ } ) ;
114+
115+ test ( 'should render an empty string if attribute is not highlighted' , ( ) => {
116+ const result = {
117+ _highlightResult : { }
118+ } ;
119+
120+ const vm = new Vue ( {
121+ template : '<highlight attributeName="attr" :result="result">' ,
122+ render ( h ) {
123+ return h ( 'highlight' , {
124+ props : {
125+ attributeName : 'attr' ,
126+ result : result
127+ }
128+ } ) ;
129+ } ,
130+ components : {
131+ Highlight
132+ }
133+ } ) . $mount ( ) ;
134+
135+
112136 expect ( vm . $el . outerHTML ) . toMatchSnapshot ( ) ;
113137} ) ;
You can’t perform that action at this time.
0 commit comments