Skip to content

Commit 8a2186b

Browse files
committed
refactor: throw error when vine.object is constructed without properties
Closes: #17
1 parent 715e761 commit 8a2186b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/schema/object/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ export class VineObject<
9797
}
9898

9999
constructor(properties: Properties, options?: FieldOptions, validations?: Validation<any>[]) {
100+
if (!properties) {
101+
throw new Error(
102+
'Missing properties for "vine.object". Use an empty object if you do not want to validate any specific fields'
103+
)
104+
}
100105
super(options, validations)
101106
this.#properties = properties
102107
}

tests/integration/schema/object.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import { test } from '@japa/runner'
1111
import vine from '../../../index.js'
1212

1313
test.group('VineObject | flat object', () => {
14+
test('fail to construct schema when object is instantiated without object', async ({
15+
assert,
16+
}) => {
17+
assert.throws(
18+
// @ts-expect-error
19+
() => vine.object(),
20+
'Missing properties for "vine.object". Use an empty object if you do not want to validate any specific fields'
21+
)
22+
})
23+
1424
test('fail when value is not an object', async ({ assert }) => {
1525
const schema = vine.object({
1626
username: vine.string(),

0 commit comments

Comments
 (0)