From ece926a59f53c72b51e8250ef97393900c0b7227 Mon Sep 17 00:00:00 2001 From: Gilmore Davidson Date: Fri, 29 Dec 2023 21:42:12 +1100 Subject: [PATCH] Add test for valueOf behaviour with invalid moments (#1075) Co-authored-by: Tmk --- tests/moment-timezone/default.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/moment-timezone/default.js b/tests/moment-timezone/default.js index af6c7ec8f..6cd7c236b 100644 --- a/tests/moment-timezone/default.js +++ b/tests/moment-timezone/default.js @@ -72,5 +72,19 @@ exports.default = { 'resetting default timezone should not affect existing moments' ); t.done(); + }, + valueOf : function (t) { + moment.tz.setDefault(); + t.ok( + Number.isNaN(moment('2023/10/06', ['H', 'HH', 'HH:mm'], true).valueOf()), + 'invalid moment should return NaN for .valueOf()' + ); + // https://github.com/moment/moment-timezone/issues/1075 + moment.tz.setDefault('America/New_York'); + t.ok( + Number.isNaN(moment('2023/10/06', ['H', 'HH', 'HH:mm'], true).valueOf()), + 'invalid moment with default zone should return NaN for .valueOf()' + ); + t.done(); } };