1
1
import { expect } from 'chai' ;
2
2
import { describe , it } from 'mocha' ;
3
3
4
- import { dedent } from '../dedent' ;
4
+ import { dedent , dedentString } from '../dedent' ;
5
5
6
- describe ( 'dedent ' , ( ) => {
6
+ describe ( 'dedentString ' , ( ) => {
7
7
it ( 'removes indentation in typical usage' , ( ) => {
8
- const output = dedent `
8
+ const output = dedentString ( `
9
9
type Query {
10
10
me: User
11
11
}
@@ -14,7 +14,7 @@ describe('dedent', () => {
14
14
id: ID
15
15
name: String
16
16
}
17
- ` ;
17
+ ` ) ;
18
18
expect ( output ) . to . equal (
19
19
[
20
20
'type Query {' ,
@@ -30,23 +30,23 @@ describe('dedent', () => {
30
30
} ) ;
31
31
32
32
it ( 'removes only the first level of indentation' , ( ) => {
33
- const output = dedent `
33
+ const output = dedentString ( `
34
34
first
35
35
second
36
36
third
37
37
fourth
38
- ` ;
38
+ ` ) ;
39
39
expect ( output ) . to . equal (
40
40
[ 'first' , ' second' , ' third' , ' fourth' ] . join ( '\n' ) ,
41
41
) ;
42
42
} ) ;
43
43
44
44
it ( 'does not escape special characters' , ( ) => {
45
- const output = dedent `
45
+ const output = dedentString ( `
46
46
type Root {
47
47
field(arg: String = "wi\th de\fault"): String
48
48
}
49
- ` ;
49
+ ` ) ;
50
50
expect ( output ) . to . equal (
51
51
[
52
52
'type Root {' ,
@@ -57,38 +57,49 @@ describe('dedent', () => {
57
57
} ) ;
58
58
59
59
it ( 'also removes indentation using tabs' , ( ) => {
60
- const output = dedent `
60
+ const output = dedentString ( `
61
61
\t\t type Query {
62
62
\t\t me: User
63
63
\t\t }
64
- ` ;
64
+ ` ) ;
65
65
expect ( output ) . to . equal ( [ 'type Query {' , ' me: User' , '}' ] . join ( '\n' ) ) ;
66
66
} ) ;
67
67
68
68
it ( 'removes leading and trailing newlines' , ( ) => {
69
- const output = dedent `
69
+ const output = dedentString ( `
70
70
71
71
72
72
type Query {
73
73
me: User
74
74
}
75
75
76
76
77
- ` ;
77
+ ` ) ;
78
78
expect ( output ) . to . equal ( [ 'type Query {' , ' me: User' , '}' ] . join ( '\n' ) ) ;
79
79
} ) ;
80
80
81
81
it ( 'removes all trailing spaces and tabs' , ( ) => {
82
- const output = dedent `
82
+ const output = dedentString ( `
83
83
type Query {
84
84
me: User
85
85
}
86
- \t\t \t ` ;
86
+ \t\t \t ` ) ;
87
87
expect ( output ) . to . equal ( [ 'type Query {' , ' me: User' , '}' ] . join ( '\n' ) ) ;
88
88
} ) ;
89
89
90
90
it ( 'works on text without leading newline' , ( ) => {
91
- const output = dedent ` type Query {
91
+ const output = dedentString ( ` type Query {
92
+ me: User
93
+ }
94
+ ` ) ;
95
+ expect ( output ) . to . equal ( [ 'type Query {' , ' me: User' , '}' ] . join ( '\n' ) ) ;
96
+ } ) ;
97
+ } ) ;
98
+
99
+ describe ( 'dedent' , ( ) => {
100
+ it ( 'removes indentation in typical usage' , ( ) => {
101
+ const output = dedent `
102
+ type Query {
92
103
me: User
93
104
}
94
105
` ;
0 commit comments