Skip to content

Commit b281abb

Browse files
authored
docs: clarify ValidationStrategy object behavior (#415)
1 parent 42a30ea commit b281abb

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

packages/object-schema/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ Instead of specifying a `validate()` method, you can specify one of the followin
115115
- `"array"` - value must be an array.
116116
- `"boolean"` - value must be a boolean.
117117
- `"number"` - value must be a number.
118-
- `"object"` - value must be an object.
119-
- `"object?"` - value must be an object or null.
118+
- `"object"` - value must be a non-null object, including arrays and non-plain objects.
119+
- `"object?"` - value must be an object or null, including arrays and non-plain objects.
120120
- `"string"` - value must be a string.
121121
- `"string!"` - value must be a non-empty string.
122122

packages/object-schema/tests/validation-strategy.test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,18 @@ describe("ValidationStrategy", () => {
7575
});
7676

7777
describe("object", () => {
78-
it("should not throw an error when the value is an object", () => {
78+
it("should not throw an error when the value is a plain object", () => {
7979
ValidationStrategy.object({});
8080
});
8181

82+
it("should not throw an error when the value is an array", () => {
83+
ValidationStrategy.object([]);
84+
});
85+
86+
it("should not throw an error when the value is a non-plain object", () => {
87+
ValidationStrategy.object(new Date());
88+
});
89+
8290
it("should throw an error when the value is null", () => {
8391
assert.throws(() => {
8492
ValidationStrategy.object(null);
@@ -117,10 +125,18 @@ describe("ValidationStrategy", () => {
117125
});
118126

119127
describe("object?", () => {
120-
it("should not throw an error when the value is an object", () => {
128+
it("should not throw an error when the value is a plain object", () => {
121129
ValidationStrategy["object?"]({});
122130
});
123131

132+
it("should not throw an error when the value is an array", () => {
133+
ValidationStrategy["object?"]([]);
134+
});
135+
136+
it("should not throw an error when the value is a non-plain object", () => {
137+
ValidationStrategy["object?"](new Date());
138+
});
139+
124140
it("should not throw an error when the value is null", () => {
125141
ValidationStrategy["object?"](null);
126142
});

0 commit comments

Comments
 (0)