@@ -129,18 +129,36 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
129
129
. catch ( throwNextTick ) ;
130
130
}
131
131
132
- // Test that appendFile does not accept numbers (callback API).
133
- [ false , 5 , { } , [ ] , null , undefined ] . forEach ( ( data ) => {
132
+ // Test that appendFile does not accept invalid data type (callback API).
133
+ [ false , 5 , { } , [ ] , null , undefined ] . forEach ( async ( data ) => {
134
134
const errObj = {
135
135
code : 'ERR_INVALID_ARG_TYPE' ,
136
136
message : / " d a t a " | " b u f f e r " /
137
137
} ;
138
+ const filename = join ( tmpdir . path , 'append-invalid-data.txt' ) ;
139
+
140
+ assert . throws (
141
+ ( ) => fs . appendFile ( filename , data , common . mustNotCall ( ) ) ,
142
+ errObj
143
+ ) ;
144
+
138
145
assert . throws (
139
- ( ) => fs . appendFile ( 'foobar' , data , common . mustNotCall ( ) ) ,
146
+ ( ) => fs . appendFileSync ( filename , data ) ,
140
147
errObj
141
148
) ;
142
- assert . throws ( ( ) => fs . appendFileSync ( 'foobar' , data ) , errObj ) ;
143
- assert . rejects ( fs . promises . appendFile ( 'foobar' , data ) , errObj ) ;
149
+
150
+ await assert . rejects (
151
+ fs . promises . appendFile ( filename , data ) ,
152
+ errObj
153
+ ) ;
154
+ // The filename shouldn't exist if throwing error.
155
+ assert . throws (
156
+ ( ) => fs . statSync ( filename ) ,
157
+ {
158
+ code : 'ENOENT' ,
159
+ message : / n o s u c h f i l e o r d i r e c t o r y /
160
+ }
161
+ ) ;
144
162
} ) ;
145
163
146
164
// Test that appendFile accepts file descriptors (callback API).
0 commit comments