@@ -96,6 +96,17 @@ describe('Change', () => {
96
96
let sourceFile = path . join ( sourcePath , 'remove-replace-file.txt' ) ;
97
97
expect ( ( ) => new ReplaceChange ( sourceFile , - 6 , 'hello' , ' world!' ) ) . toThrow ( ) ;
98
98
} ) ;
99
+ it ( 'fails for invalid replacement' , ( ) => {
100
+ let sourceFile = path . join ( sourcePath , 'replace-file.txt' ) ;
101
+ let changeInstance = new ReplaceChange ( sourceFile , 0 , 'foobar' , '' ) ;
102
+ return changeInstance
103
+ . apply ( NodeHost )
104
+ . then ( ( ) => expect ( false ) . toBe ( true ) , err => {
105
+ // Check that the message contains the string to replace and the string from the file.
106
+ expect ( err . message ) . toContain ( 'foobar' ) ;
107
+ expect ( err . message ) . toContain ( 'import' ) ;
108
+ } ) ;
109
+ } ) ;
99
110
it ( 'adds string to the position of an empty string' , ( ) => {
100
111
let sourceFile = path . join ( sourcePath , 'replace-file.txt' ) ;
101
112
let changeInstance = new ReplaceChange ( sourceFile , 9 , '' , 'BarComponent, ' ) ;
@@ -108,7 +119,7 @@ describe('Change', () => {
108
119
} ) ;
109
120
it ( 'removes the given string only if an empty string to add is given' , ( ) => {
110
121
let sourceFile = path . join ( sourcePath , 'remove-replace-file.txt' ) ;
111
- let changeInstance = new ReplaceChange ( sourceFile , 9 , ' as foo' , '' ) ;
122
+ let changeInstance = new ReplaceChange ( sourceFile , 8 , ' as foo' , '' ) ;
112
123
return changeInstance
113
124
. apply ( NodeHost )
114
125
. then ( ( ) => readFile ( sourceFile , 'utf8' ) )
0 commit comments