1
- import { stringInterpolation } from "../index"
1
+ import { stringInterpolation } from "../index" ;
2
2
3
3
describe ( "stringInterpolation()" , ( ) => {
4
4
test ( "Empty" , ( ) => {
5
5
expect ( ( ) => {
6
6
stringInterpolation ( "" , {
7
7
world : "world" ,
8
- } )
9
- } ) . toThrow ( "Empty string" )
10
- } )
8
+ } ) ;
9
+ } ) . toThrow ( "Empty string" ) ;
10
+ } ) ;
11
11
test ( "Incorrect variable count" , ( ) => {
12
12
expect ( ( ) => {
13
13
stringInterpolation ( "Hello {{world}}" , {
14
14
world : "world with varialbe" ,
15
15
extraVariable : "this is unnecessary" ,
16
- } )
17
- } ) . toThrow ( "Variable count mismatch" )
18
- } )
16
+ } ) ;
17
+ } ) . toThrow ( "Variable count mismatch" ) ;
18
+ } ) ;
19
19
test ( "Variable not found" , ( ) => {
20
20
expect ( ( ) =>
21
21
stringInterpolation ( "Hello {{world}}" , {
22
22
wrongVariable : "world" ,
23
23
} )
24
- ) . toThrow ( "Variable 'world' not found" )
25
- } )
24
+ ) . toThrow ( "Variable 'world' not found" ) ;
25
+ } ) ;
26
26
test ( "Interpolate single variable" , ( ) => {
27
27
expect (
28
28
stringInterpolation ( "Hello {{world}}" , {
29
29
world : "world with variable" ,
30
30
} )
31
- ) . toBe ( "Hello world with variable" )
32
- } )
31
+ ) . toBe ( "Hello world with variable" ) ;
32
+ } ) ;
33
33
test ( "Interpolate single variable and return raw result with passed in option" , ( ) => {
34
34
expect (
35
35
stringInterpolation (
@@ -39,16 +39,16 @@ describe("stringInterpolation()", () => {
39
39
} ,
40
40
{ raw : true }
41
41
)
42
- ) . toStrictEqual ( [ "Hello " , "world with variable" ] )
43
- } )
42
+ ) . toStrictEqual ( [ "Hello " , "world with variable" ] ) ;
43
+ } ) ;
44
44
test ( "Interpolate two variables" , ( ) => {
45
45
expect (
46
46
stringInterpolation ( "Hello {{world}} and {{anotherVariable}}" , {
47
47
world : "world with variable" ,
48
48
anotherVariable : "another variable" ,
49
49
} )
50
- ) . toBe ( "Hello world with variable and another variable" )
51
- } )
50
+ ) . toBe ( "Hello world with variable and another variable" ) ;
51
+ } ) ;
52
52
test ( "Interpolation variable contains a function" , ( ) => {
53
53
expect (
54
54
stringInterpolation ( "Hello {{world}} and {{anotherVariable}}" , {
@@ -60,6 +60,11 @@ describe("stringInterpolation()", () => {
60
60
"world with variable" ,
61
61
" and " ,
62
62
expect . any ( Function ) ,
63
- ] )
64
- } )
65
- } )
63
+ ] ) ;
64
+ } ) ;
65
+ test ( "Interpolation string contains a variable name which should remain the same" , ( ) => {
66
+ expect ( stringInterpolation ( "foo{{foo}}" , { foo : "bar" } ) ) . toStrictEqual (
67
+ "foobar" // todo: fix - returns "barbar"
68
+ ) ;
69
+ } ) ;
70
+ } ) ;
0 commit comments