@@ -921,6 +921,52 @@ describe( "Autolinker", function() {
921
921
var returnTrueFn = function ( ) { return true ; } ,
922
922
returnFalseFn = function ( ) { return false ; } ;
923
923
924
+
925
+ it ( "should populate a UrlMatch object with the appropriate properties" , function ( ) {
926
+ var replaceFnCallCount = 0 ;
927
+ var result = Autolinker . link ( "Website: asdf.com " , { // purposeful trailing space
928
+ replaceFn : function ( autolinker , match ) {
929
+ replaceFnCallCount ++ ;
930
+
931
+ expect ( match . getMatchedText ( ) ) . toBe ( 'asdf.com' ) ;
932
+ expect ( match . getUrl ( ) ) . toBe ( 'http://asdf.com' ) ;
933
+ }
934
+ } ) ;
935
+
936
+ expect ( replaceFnCallCount ) . toBe ( 1 ) ; // make sure the replaceFn was called
937
+ } ) ;
938
+
939
+
940
+ it ( "should populate an EmailMatch object with the appropriate properties" , function ( ) {
941
+ var replaceFnCallCount = 0 ;
942
+ var result = Autolinker . link ( "Email: asdf@asdf.com " , { // purposeful trailing space
943
+ replaceFn : function ( autolinker , match ) {
944
+ replaceFnCallCount ++ ;
945
+
946
+ expect ( match . getMatchedText ( ) ) . toBe ( 'asdf@asdf.com' ) ;
947
+ expect ( match . getEmail ( ) ) . toBe ( 'asdf@asdf.com' ) ;
948
+ }
949
+ } ) ;
950
+
951
+ expect ( replaceFnCallCount ) . toBe ( 1 ) ; // make sure the replaceFn was called
952
+ } ) ;
953
+
954
+
955
+ it ( "should populate a TwitterMatch object with the appropriate properties" , function ( ) {
956
+ var replaceFnCallCount = 0 ;
957
+ var result = Autolinker . link ( "Twitter: @myTwitter " , { // purposeful trailing space
958
+ replaceFn : function ( autolinker , match ) {
959
+ replaceFnCallCount ++ ;
960
+
961
+ expect ( match . getMatchedText ( ) ) . toBe ( '@myTwitter' ) ;
962
+ expect ( match . getTwitterHandle ( ) ) . toBe ( 'myTwitter' ) ;
963
+ }
964
+ } ) ;
965
+
966
+ expect ( replaceFnCallCount ) . toBe ( 1 ) ; // make sure the replaceFn was called
967
+ } ) ;
968
+
969
+
924
970
it ( "should replace the match as Autolinker would normally do when `true` is returned from the `replaceFn`" , function ( ) {
925
971
var result = Autolinker . link ( "Website: asdf.com, Email: asdf@asdf.com, Twitter: @asdf" , {
926
972
newWindow : false , // just to suppress the target="_blank" from the output for this test
0 commit comments