From 764b330d131ed248269703aa30054b2944884007 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Thu, 25 Sep 2025 15:06:30 -0400 Subject: [PATCH] Add unit tests --- .../app/js/components/tests/Units.test.jsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/static/app/js/components/tests/Units.test.jsx b/app/static/app/js/components/tests/Units.test.jsx index 4aed9a5a..1904e192 100644 --- a/app/static/app/js/components/tests/Units.test.jsx +++ b/app/static/app/js/components/tests/Units.test.jsx @@ -125,17 +125,22 @@ describe('Metric conversion', () => { const km = metric.length(2000); const mi = imperial.length(3220); + const ft2 = imperial.area(100); expect(km.unit.abbr).toBe("km"); expect(km.value).toBe(2); expect(mi.unit.abbr).toBe("mi"); - expect(Math.round(mi.value)).toBe(2) + expect(Math.round(mi.value)).toBe(2); + expect(ft2.unit.abbr).toBe("ft²"); + expect(Math.round(ft2.value)).toBe(1076); expect(toMetric(km).toString()).toBe("2,000 m"); expect(toMetric(mi).toString()).toBe("3,220 m"); + expect(ft2.toString()).toBe("1,076.39 ft²"); expect(toMetric(km).value).toBe(2000); expect(toMetric(mi).value).toBe(3220); + expect(Math.round(toMetric(ft2).value)).toBe(100); const celsius = metric.temperature(50); const fahrenheit = imperial.temperature(50); @@ -146,3 +151,13 @@ describe('Metric conversion', () => { expect(toMetric(fahrenheit).value).toBe(50); }); }); + +describe('Handle NaN values', () => { + it('it should handle NaN values properly', () => { + const { metric } = systems; + + const nan = metric.area(Infinity - Infinity); + expect(nan.toString()).toBe("NaN"); + expect(nan.constructor.name).toBe("NanUnit"); + }); +});