Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions lib/ObjectSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,7 @@ const ObjectSchema = ({ schema = initialState, ...options } = {}) => {
}
const src = base._getState()
const extended = combineDeepmerge(src, schema)
const {
valueOf,
isFluentSchema,
FLUENT_SCHEMA,
_getState,
extend
} = ObjectSchema({ schema: extended, ...options })
return { valueOf, isFluentSchema, FLUENT_SCHEMA, _getState, extend }
return ObjectSchema({ schema: extended, ...options })
},

/**
Expand Down
41 changes: 30 additions & 11 deletions test/ObjectSchema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,17 +862,36 @@ describe('ObjectSchema', () => {
)
})

it('throws an error if you append a new prop after extend', () => {
assert.throws(
() => {
const base = S.object()
S.object().extend(base).prop('foo')
},
(err) =>
// err instanceof S.FluentSchemaError &&
err instanceof TypeError &&
err.message === 'S.object(...).extend(...).prop is not a function'
)
it('returns a chainable schema instance after extend', () => {
const base = S.object()
.prop('one', S.number())
.prop('two', S.number())

const extended = S.object()
.prop('three', S.number())
.prop('four', S.number())
.extend(base)
.prop('five', S.number())

assert.deepStrictEqual(extended.without(['one']).valueOf(), {
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
properties: {
two: { type: 'number' },
three: { type: 'number' },
four: { type: 'number' },
five: { type: 'number' }
}
})

assert.deepStrictEqual(extended.only(['three', 'five']).valueOf(), {
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
properties: {
three: { type: 'number' },
five: { type: 'number' }
}
})
})
})

Expand Down
Loading