Skip to content

Commit

Permalink
tests: Verify function default values.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 21, 2021
1 parent 6319a06 commit ac456bc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions optimal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions optimal/tests/schemas/func.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ describe('func()', () => {

runCommonTests(() => func(), noop, { defaultValue: undefined });

it('supports default values', () => {
const spy = jest.fn();
schema = func<AnyFunction>(() => spy);

expect(schema.validate(undefined)).toBe(spy);
});

describe('type()', () => {
it('returns "function"', () => {
expect(func().type()).toBe('function');
Expand Down

0 comments on commit ac456bc

Please sign in to comment.