diff --git a/optimal/CHANGELOG.md b/optimal/CHANGELOG.md index 66c6896..1386d0f 100644 --- a/optimal/CHANGELOG.md +++ b/optimal/CHANGELOG.md @@ -18,6 +18,7 @@ changelog will use the new verbiage, but may affect previous APIs. - Updated `optimal()` to no longer accept the object to validate and build as the 1st argument. Instead a `validate()` function is returned, in which that object should be passed to. Because of this change, TypeScript types are more powerful and accurate. - Updated `array()` to no longer accept a schema as an argument, use `array().of()` instead. - Updated `func()` to not be nullable by default. Instead uses `undefined`. +- Updated `func()` default values to now be factoried (function returns a function). - Updated `instance()` to no longer accept a schema as an argument, use `instance().of()` instead. - Updated `object()` to no longer accept a schema as an argument, use `object().of()` instead. - Updated `union()` to no longer accept a list of schemas as an argument, use `union().of()` instead. diff --git a/optimal/tests/schemas/func.test.ts b/optimal/tests/schemas/func.test.ts index b8529b5..25efa70 100644 --- a/optimal/tests/schemas/func.test.ts +++ b/optimal/tests/schemas/func.test.ts @@ -18,6 +18,13 @@ describe('func()', () => { runCommonTests(() => func(), noop, { defaultValue: undefined }); + it('supports default values', () => { + const spy = jest.fn(); + schema = func(() => spy); + + expect(schema.validate(undefined)).toBe(spy); + }); + describe('type()', () => { it('returns "function"', () => { expect(func().type()).toBe('function');