11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This tests that the errors thrown from fs.close and fs.closeSync 41cb0ef41Sopenharmony_ci// include the desired properties 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst fs = require('fs'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci['', false, null, undefined, {}, []].forEach((input) => { 111cb0ef41Sopenharmony_ci const errObj = { 121cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 131cb0ef41Sopenharmony_ci name: 'TypeError', 141cb0ef41Sopenharmony_ci message: 'The "fd" argument must be of type number.' + 151cb0ef41Sopenharmony_ci common.invalidArgTypeHelper(input) 161cb0ef41Sopenharmony_ci }; 171cb0ef41Sopenharmony_ci assert.throws(() => fs.close(input), errObj); 181cb0ef41Sopenharmony_ci assert.throws(() => fs.closeSync(input), errObj); 191cb0ef41Sopenharmony_ci}); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci{ 221cb0ef41Sopenharmony_ci // Test error when cb is not a function 231cb0ef41Sopenharmony_ci const fd = fs.openSync(__filename, 'r'); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci const errObj = { 261cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 271cb0ef41Sopenharmony_ci name: 'TypeError' 281cb0ef41Sopenharmony_ci }; 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci ['', false, null, {}, []].forEach((input) => { 311cb0ef41Sopenharmony_ci assert.throws(() => fs.close(fd, input), errObj); 321cb0ef41Sopenharmony_ci }); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci fs.closeSync(fd); 351cb0ef41Sopenharmony_ci} 36