diff --git a/src/datetime.js b/src/datetime.js index 0958787ad..9d9040ef6 100644 --- a/src/datetime.js +++ b/src/datetime.js @@ -514,6 +514,10 @@ export default class DateTime { * @access private */ constructor(config) { + if (!config) { + return DateTime.invalid("no config supplied"); + } + const zone = config.zone || Settings.defaultZone; let invalid = diff --git a/src/duration.js b/src/duration.js index c1135defe..bf0e8320e 100644 --- a/src/duration.js +++ b/src/duration.js @@ -218,6 +218,10 @@ export default class Duration { * @private */ constructor(config) { + if (!config) { + return Duration.invalid("no config supplied"); + } + const accurate = config.conversionAccuracy === "longterm" || false; let matrix = accurate ? accurateMatrix : casualMatrix; diff --git a/src/interval.js b/src/interval.js index 6073d028d..870ea6564 100644 --- a/src/interval.js +++ b/src/interval.js @@ -41,6 +41,10 @@ export default class Interval { * @private */ constructor(config) { + if (!config) { + return Interval.invalid("no config supplied"); + } + /** * @access private */ diff --git a/test/datetime/create.test.js b/test/datetime/create.test.js index 67613a610..31d0885b7 100644 --- a/test/datetime/create.test.js +++ b/test/datetime/create.test.js @@ -9,6 +9,15 @@ const withDefaultLocale = Helpers.withDefaultLocale, withthrowOnInvalid = Helpers.setUnset("throwOnInvalid"), withDefaultZone = Helpers.withDefaultZone; +//------ +// new +//------ +test("Default constructor works and returns an invalid instance", () => { + const datetime = new DateTime(); + expect(datetime.isValid).toBe(false); + expect(datetime.invalidReason).toBe("no config supplied"); +}); + //------ // .now() //------ diff --git a/test/duration/create.test.js b/test/duration/create.test.js index 1a6cbb228..3fae9c4b0 100644 --- a/test/duration/create.test.js +++ b/test/duration/create.test.js @@ -2,6 +2,15 @@ import { Duration } from "../../src/luxon"; +//------ +// new +//------ +test("Default constructor works and returns an invalid instance", () => { + const duration = new Duration(); + expect(duration.isValid).toBe(false); + expect(duration.invalidReason).toBe("no config supplied"); +}); + //------ // .fromObject() //------- diff --git a/test/interval/create.test.js b/test/interval/create.test.js index bab2a75e3..3e2b04005 100644 --- a/test/interval/create.test.js +++ b/test/interval/create.test.js @@ -4,6 +4,15 @@ import Helpers from "../helpers"; const withThrowOnInvalid = Helpers.setUnset("throwOnInvalid"); +//------ +// new +//------ +test("Default constructor works and returns an invalid instance", () => { + const interval = new Interval(); + expect(interval.isValid).toBe(false); + expect(interval.invalidReason).toBe("no config supplied"); +}); + //------ // .fromObject() //-------