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 27
27
const attributeName = ctx .props .attributeName
28
28
const tagName = ctx .props .tagName
29
29
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
+ }
33
34
34
- let attributeValue = result ._highlightResult [attributeName].value
35
35
if (ctx .props .escapeHtml === true ) {
36
36
attributeValue = escapeHtml (attributeValue)
37
37
}
Original file line number Diff line number Diff line change @@ -17,3 +17,5 @@ exports[`renders proper HTML 1`] = `
17
17
<span class = " ais-highlight" >con
18
18
<mark >ten</mark >t</span >
19
19
` ;
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', () => {
109
109
}
110
110
} ) . $mount ( ) ;
111
111
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
+
112
136
expect ( vm . $el . outerHTML ) . toMatchSnapshot ( ) ;
113
137
} ) ;
You can’t perform that action at this time.
0 commit comments