4
4
* you may not use this file except in compliance with the Elastic License.
5
5
*/
6
6
7
- import { renderMustacheString , renderMustacheObject } from './mustache_renderer' ;
7
+ import { renderMustacheString , renderMustacheObject , Escape } from './mustache_renderer' ;
8
8
9
9
const variables = {
10
10
a : 1 ,
@@ -14,7 +14,9 @@ const variables = {
14
14
e : undefined ,
15
15
f : {
16
16
g : 3 ,
17
+ h : null ,
17
18
} ,
19
+ i : [ 42 , 43 , 44 ] ,
18
20
lt : '<' ,
19
21
gt : '>' ,
20
22
amp : '&' ,
@@ -29,15 +31,26 @@ const variables = {
29
31
30
32
describe ( 'mustache_renderer' , ( ) => {
31
33
describe ( 'renderMustacheString()' , ( ) => {
32
- it ( 'handles basic templating that does not need escaping' , ( ) => {
33
- expect ( renderMustacheString ( '' , variables , 'none' ) ) . toBe ( '' ) ;
34
- expect ( renderMustacheString ( '{{a}}' , variables , 'none' ) ) . toBe ( '1' ) ;
35
- expect ( renderMustacheString ( '{{b}}' , variables , 'none' ) ) . toBe ( '2' ) ;
36
- expect ( renderMustacheString ( '{{c}}' , variables , 'none' ) ) . toBe ( 'false' ) ;
37
- expect ( renderMustacheString ( '{{d}}' , variables , 'none' ) ) . toBe ( '' ) ;
38
- expect ( renderMustacheString ( '{{e}}' , variables , 'none' ) ) . toBe ( '' ) ;
39
- expect ( renderMustacheString ( '{{f.g}}' , variables , 'none' ) ) . toBe ( '3' ) ;
40
- } ) ;
34
+ for ( const escapeVal of [ 'none' , 'slack' , 'markdown' , 'json' ] ) {
35
+ const escape = escapeVal as Escape ;
36
+
37
+ it ( `handles basic templating that does not need escaping for ${ escape } ` , ( ) => {
38
+ expect ( renderMustacheString ( '' , variables , escape ) ) . toBe ( '' ) ;
39
+ expect ( renderMustacheString ( '{{a}}' , variables , escape ) ) . toBe ( '1' ) ;
40
+ expect ( renderMustacheString ( '{{b}}' , variables , escape ) ) . toBe ( '2' ) ;
41
+ expect ( renderMustacheString ( '{{c}}' , variables , escape ) ) . toBe ( 'false' ) ;
42
+ expect ( renderMustacheString ( '{{d}}' , variables , escape ) ) . toBe ( '' ) ;
43
+ expect ( renderMustacheString ( '{{e}}' , variables , escape ) ) . toBe ( '' ) ;
44
+ if ( escape === 'markdown' ) {
45
+ expect ( renderMustacheString ( '{{f}}' , variables , escape ) ) . toBe ( '\\[object Object\\]' ) ;
46
+ } else {
47
+ expect ( renderMustacheString ( '{{f}}' , variables , escape ) ) . toBe ( '[object Object]' ) ;
48
+ }
49
+ expect ( renderMustacheString ( '{{f.g}}' , variables , escape ) ) . toBe ( '3' ) ;
50
+ expect ( renderMustacheString ( '{{f.h}}' , variables , escape ) ) . toBe ( '' ) ;
51
+ expect ( renderMustacheString ( '{{i}}' , variables , escape ) ) . toBe ( '42,43,44' ) ;
52
+ } ) ;
53
+ }
41
54
42
55
it ( 'handles escape:none with commonly escaped strings' , ( ) => {
43
56
expect ( renderMustacheString ( '{{lt}}' , variables , 'none' ) ) . toBe ( variables . lt ) ;
0 commit comments