From cda5e429059d2021d76eaa53d82d7e9edf67b6cf Mon Sep 17 00:00:00 2001 From: John Madhavan-Reese Date: Mon, 25 Aug 2014 12:20:54 -0400 Subject: [PATCH] Tests for floating point errors in duration .as method output. --- test/moment/duration.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/moment/duration.js b/test/moment/duration.js index 2e6e483f1..42e569900 100644 --- a/test/moment/duration.js +++ b/test/moment/duration.js @@ -513,6 +513,23 @@ exports.duration = { test.done(); }, + 'as getters for small units' : function (test) { + var dS = moment.duration(1, 'milliseconds'), + ds = moment.duration(3, 'seconds'), + dm = moment.duration(13, 'minutes'); + + test.expect(6); + // Tests for issue #1867. + // Floating point errors for small duration units were introduced in version 2.8.0. + test.equal(dS.as('milliseconds'), 1, 'as("milliseconds")'); + test.equal(dS.asMilliseconds(), 1, 'asMilliseconds()'); + test.equal(ds.as('seconds'), 3, 'as("seconds")'); + test.equal(ds.asSeconds(), 3, 'asSeconds()'); + test.equal(dm.as('minutes'), 13, 'as("minutes")'); + test.equal(dm.asMinutes(), 13, 'asMinutes()'); + test.done(); + }, + 'isDuration' : function (test) { test.expect(3); test.ok(moment.isDuration(moment.duration(12345678)), 'correctly says true'); -- 2.47.2