forked from rjsf-team/react-jsonschema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
isObject should return false for Date as well as File, null, and Array (
rjsf-team#3292) * Tests for existing 'isObject' functionality * isObject should return false for Date as well as File, null, and Array Without this, assigning dates to the form's value instead merges them with a default value for objects of `{}` (in mergeDefaultsWithFormData), which stops them being dates. * Corrected changelog entry * Update CHANGELOG.md * Lint formatting tests Co-authored-by: Heath C <[email protected]>
- Loading branch information
1 parent
f95d7ae
commit 7a2f5dc
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { isObject } from "../src"; | ||
|
||
const NON_OBJECTS = ["string", 10, NaN, true, null, undefined]; | ||
|
||
const OBJECTS = [{ plain: "object" }, new Object(), new Map()]; | ||
|
||
describe("isObject()", () => { | ||
it("returns false when a non-object is provided", () => { | ||
NON_OBJECTS.forEach( | ||
(nonObject: string | number | boolean | null | undefined) => { | ||
expect(isObject(nonObject)).toBe(false); | ||
} | ||
); | ||
}); | ||
it("returns false when a File is provided", () => { | ||
const file = new File(["test"], "test.txt"); | ||
expect(isObject(file)).toBe(false); | ||
}); | ||
it("returns false when a Date is provided", () => { | ||
const date = new Date(); | ||
expect(isObject(date)).toBe(false); | ||
}); | ||
it("returns false when an array is provided", () => { | ||
expect(isObject(["foo"])).toBe(false); | ||
}); | ||
it("returns true when an object is provided", () => { | ||
OBJECTS.forEach((object: any) => { | ||
expect(isObject(object)).toBe(true); | ||
}); | ||
}); | ||
}); |