File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 1
- export function escape ( val ) {
2
- return val . replace ( / ' / g, `\\'` ) ;
1
+ export function wrapInQuotes ( val ) {
2
+ if ( ! val . includes ( `'` ) ) {
3
+ return `'${ val } '` ;
4
+ }
5
+
6
+ if ( ! val . includes ( '"' ) ) {
7
+ return `"${ val } "` ;
8
+ }
9
+
10
+ if ( ! val . includes ( '`' ) ) {
11
+ return `\`${ val } \`` ;
12
+ }
13
+
14
+ return `'${ val . replace ( / ' / g, `\\'` ) } '` ;
3
15
}
4
16
5
17
export function getFieldName ( method ) {
@@ -10,11 +22,13 @@ export function getExpression({ method, data }) {
10
22
const field = getFieldName ( method ) ;
11
23
12
24
if ( method === 'getByRole' && data . role && data . name ) {
13
- return `screen.getByRole('${ data . role } ', { name: '${ escape ( data . name ) } ' })` ;
25
+ return `screen.getByRole('${ data . role } ', { name: ${ wrapInQuotes (
26
+ data . name ,
27
+ ) } })`;
14
28
}
15
29
16
30
if ( data [ field ] ) {
17
- return `screen.${ method } (' ${ escape ( data [ field ] ) } ' )` ;
31
+ return `screen.${ method } (${ wrapInQuotes ( data [ field ] ) } )` ;
18
32
}
19
33
20
34
return '' ;
You can’t perform that action at this time.
0 commit comments