From 6aed32c57986b90290459e155aca20b962cd3829 Mon Sep 17 00:00:00 2001 From: Luca Maraschi Date: Thu, 16 Mar 2017 23:58:16 +0100 Subject: [PATCH] test: add tests for unixtimestamp generation This test checks for the different input types for the generation of UNIX timestamps in the fs module. PR-URL: https://github.com/nodejs/node/pull/11886 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- test/parallel/test-fs-timestamp-parsing-error.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/parallel/test-fs-timestamp-parsing-error.js diff --git a/test/parallel/test-fs-timestamp-parsing-error.js b/test/parallel/test-fs-timestamp-parsing-error.js new file mode 100644 index 00000000000000..321f80b269fa6f --- /dev/null +++ b/test/parallel/test-fs-timestamp-parsing-error.js @@ -0,0 +1,16 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const fs = require('fs'); + +[undefined, null, []].forEach((input) => { + assert.throws(() => fs._toUnixTimestamp(input), + new RegExp('^Error: Cannot parse time: ' + input + '$')); +}); + +assert.throws(() => fs._toUnixTimestamp({}), + /^Error: Cannot parse time: \[object Object\]$/); + +[1, '1', Date.now(), -1, '-1', Infinity].forEach((input) => { + assert.doesNotThrow(() => fs._toUnixTimestamp(input)); +});