From 2f4938986eed8c0058663256e02db0f088b758e4 Mon Sep 17 00:00:00 2001 From: Bernhard Pottler Date: Mon, 6 Jun 2022 08:04:52 +0200 Subject: [PATCH] test: add tests for customParseFormat.utils.js --- test/plugin/customParseFormat.utils.test.js | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/plugin/customParseFormat.utils.test.js diff --git a/test/plugin/customParseFormat.utils.test.js b/test/plugin/customParseFormat.utils.test.js new file mode 100644 index 000000000..24d2e676f --- /dev/null +++ b/test/plugin/customParseFormat.utils.test.js @@ -0,0 +1,27 @@ +import MockDate from 'mockdate' +import { daysInMonth } from '../../src/plugin/customParseFormat/utils' + +beforeEach(() => { + MockDate.set(new Date()) +}) + +afterEach(() => { + MockDate.reset() +}) + +it('Days in Month for months with constant length', () => { + expect(daysInMonth(2022, 5)).toBe(31) + expect(daysInMonth(2013, 9)).toBe(30) +}) + +it('Days in Month for february', () => { + expect(daysInMonth(2003, 2)).toBe(28) + expect(daysInMonth(2100, 2)).toBe(28) + expect(daysInMonth(2000, 2)).toBe(29) + expect(daysInMonth(2004, 2)).toBe(29) +}) + +it('Days in Month with wrong parameter types', () => { + expect(daysInMonth(Number.NaN, 5)).toBeNaN() + expect(daysInMonth(2013, Number.NaN)).toBeNaN() +})