@@ -175,6 +175,55 @@ describe('formatNumber helper', () => {
175175 } ) ;
176176} ) ;
177177
178+ describe ( 'replace helper' , ( ) => {
179+ test ( 'replaces all occurrences' , ( ) => {
180+ const url = 'https://elastic.co/{{replace value "replace-me" "with-me"}}' ;
181+
182+ expect ( compile ( url , { value : 'replace-me test replace-me' } ) ) . toMatchInlineSnapshot (
183+ `"https://elastic.co/with-me%20test%20with-me"`
184+ ) ;
185+ } ) ;
186+
187+ test ( 'can be used to remove a substring' , ( ) => {
188+ const url = 'https://elastic.co/{{replace value "Label:" ""}}' ;
189+
190+ expect ( compile ( url , { value : 'Label:Feature:Something' } ) ) . toMatchInlineSnapshot (
191+ `"https://elastic.co/Feature:Something"`
192+ ) ;
193+ } ) ;
194+
195+ test ( 'works if no matches' , ( ) => {
196+ const url = 'https://elastic.co/{{replace value "Label:" ""}}' ;
197+
198+ expect ( compile ( url , { value : 'No matches' } ) ) . toMatchInlineSnapshot (
199+ `"https://elastic.co/No%20matches"`
200+ ) ;
201+ } ) ;
202+
203+ test ( 'throws on incorrect args' , ( ) => {
204+ expect ( ( ) =>
205+ compile ( 'https://elastic.co/{{replace value "Label:"}}' , { value : 'No matches' } )
206+ ) . toThrowErrorMatchingInlineSnapshot (
207+ `"[replace]: \\"searchString\\" and \\"valueString\\" parameters expected to be strings, but not a string or missing"`
208+ ) ;
209+ expect ( ( ) =>
210+ compile ( 'https://elastic.co/{{replace value "Label:" 4}}' , { value : 'No matches' } )
211+ ) . toThrowErrorMatchingInlineSnapshot (
212+ `"[replace]: \\"searchString\\" and \\"valueString\\" parameters expected to be strings, but not a string or missing"`
213+ ) ;
214+ expect ( ( ) =>
215+ compile ( 'https://elastic.co/{{replace value 4 ""}}' , { value : 'No matches' } )
216+ ) . toThrowErrorMatchingInlineSnapshot (
217+ `"[replace]: \\"searchString\\" and \\"valueString\\" parameters expected to be strings, but not a string or missing"`
218+ ) ;
219+ expect ( ( ) =>
220+ compile ( 'https://elastic.co/{{replace value}}' , { value : 'No matches' } )
221+ ) . toThrowErrorMatchingInlineSnapshot (
222+ `"[replace]: \\"searchString\\" and \\"valueString\\" parameters expected to be strings, but not a string or missing"`
223+ ) ;
224+ } ) ;
225+ } ) ;
226+
178227describe ( 'basic string formatting helpers' , ( ) => {
179228 test ( 'lowercase' , ( ) => {
180229 const compileUrl = ( value : unknown ) =>
0 commit comments