1+ /**
2+ * Tests for elementDestinationUrl utils (hasValidMustacheOnly, isValidElementDestinationURL).
3+ * Written for 100% line and branch coverage of src/utils/elementDestinationUrl.js.
4+ */
15import {
26 isValidElementDestinationURL ,
37 hasValidMustacheOnly ,
@@ -15,13 +19,20 @@ describe('elementDestinationUrl', () => {
1519 expect ( hasValidMustacheOnly ( '{{a}}{{b}}' ) ) . toBe ( true ) ;
1620 } ) ;
1721
22+ it ( 'returns true for placeholder with spaces around variable name' , ( ) => {
23+ expect ( hasValidMustacheOnly ( '{{ x }}' ) ) . toBe ( true ) ;
24+ } ) ;
25+
1826 it ( 'returns false when string contains empty mustache {{}} or {{ }}' , ( ) => {
1927 expect ( hasValidMustacheOnly ( '{{}}' ) ) . toBe ( false ) ;
2028 expect ( hasValidMustacheOnly ( '{{ }}' ) ) . toBe ( false ) ;
2129 } ) ;
2230
23- it ( 'returns false when string has stray {{ or }} ' , ( ) => {
31+ it ( 'returns false when string has stray {{ (unclosed) ' , ( ) => {
2432 expect ( hasValidMustacheOnly ( '{{unclosed' ) ) . toBe ( false ) ;
33+ } ) ;
34+
35+ it ( 'returns false when string has stray }} after valid placeholder' , ( ) => {
2536 expect ( hasValidMustacheOnly ( '{{a}} }}' ) ) . toBe ( false ) ;
2637 } ) ;
2738
@@ -36,6 +47,7 @@ describe('elementDestinationUrl', () => {
3647 expect ( isValidElementDestinationURL ( null ) ) . toBe ( false ) ;
3748 expect ( isValidElementDestinationURL ( undefined ) ) . toBe ( false ) ;
3849 expect ( isValidElementDestinationURL ( 123 ) ) . toBe ( false ) ;
50+ expect ( isValidElementDestinationURL ( false ) ) . toBe ( false ) ;
3951 expect ( isValidElementDestinationURL ( { } ) ) . toBe ( false ) ;
4052 expect ( isValidElementDestinationURL ( [ ] ) ) . toBe ( false ) ;
4153 } ) ;
@@ -109,7 +121,7 @@ describe('elementDestinationUrl', () => {
109121 expect ( isValidElementDestinationURL ( ' https://example.com ' ) ) . toBe ( true ) ;
110122 } ) ;
111123
112- it ( 'returns false for invalid URL' , ( ) => {
124+ it ( 'returns false for invalid URL (exercises catch branch) ' , ( ) => {
113125 expect ( isValidElementDestinationURL ( 'not a url' ) ) . toBe ( false ) ;
114126 expect ( isValidElementDestinationURL ( '://bad' ) ) . toBe ( false ) ;
115127 } ) ;
0 commit comments