diff --git a/test/parallel/test-fs-promises-file-handle-write.js b/test/parallel/test-fs-promises-file-handle-write.js index 3c25842d8bf9cc..b558335c9f6c34 100644 --- a/test/parallel/test-fs-promises-file-handle-write.js +++ b/test/parallel/test-fs-promises-file-handle-write.js @@ -53,7 +53,12 @@ async function validateNonUint8ArrayWrite() { async function validateNonStringValuesWrite() { const filePathForHandle = path.resolve(tmpDir, 'tmp-non-string-write.txt'); const fileHandle = await open(filePathForHandle, 'w+'); - const nonStringValues = [123, {}, new Map()]; + const nonStringValues = [ + 123, {}, new Map(), + new String('notPrimitive'), + { toString() { return 'amObject'; } }, + { [Symbol.toPrimitive]: (hint) => 'amObject' }, + ]; for (const nonStringValue of nonStringValues) { await assert.rejects( fileHandle.write(nonStringValue), diff --git a/test/parallel/test-fs-write-sync-optional-params.js b/test/parallel/test-fs-write-sync-optional-params.js index 111ce5387b124b..c8659610070819 100644 --- a/test/parallel/test-fs-write-sync-optional-params.js +++ b/test/parallel/test-fs-write-sync-optional-params.js @@ -71,6 +71,23 @@ const buffer = Buffer.from('zyx'); 'It must be >= 0 && <= 9007199254740991. Received -1' }); + // Test if object is not interpreted as string + for (const buffer of [ + {}, + new Date(), + new String('notPrimitive'), + { toString() { return 'amObject'; } }, + { [Symbol.toPrimitive]: (hint) => 'amObject' }, + ]) { + assert.throws(() => { + fs.writeSync(fd, buffer); + }, { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: /^The "buffer" argument must be of type string or an instance of Buffer, TypedArray, or DataView/ + }); + } + fs.closeSync(fd); for (const params of [