Skip to content

Commit 1350d11

Browse files
committed
add allOf test
1 parent cd8886a commit 1350d11

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test/allof.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict'
2+
3+
const test = require('tap').test
4+
const build = require('..')
5+
6+
test('object with multiple types field', (t) => {
7+
t.plan(2)
8+
9+
const schema = {
10+
title: 'object with multiple types field',
11+
type: 'object',
12+
allOf: [
13+
{
14+
type: 'object',
15+
required: [
16+
'name'
17+
],
18+
properties: {
19+
name: {
20+
type: 'string'
21+
},
22+
tag: {
23+
type: 'string'
24+
}
25+
}
26+
},
27+
{
28+
required: [
29+
'id'
30+
],
31+
type: 'object',
32+
properties: {
33+
id: {
34+
type: 'integer'
35+
}
36+
}
37+
}
38+
]
39+
}
40+
const stringify = build(schema)
41+
42+
try {
43+
const value = stringify({
44+
id: 1,
45+
name: 'string'
46+
})
47+
t.is(value, '{"id":1,"name":"string"}')
48+
} catch (e) {
49+
t.fail()
50+
}
51+
52+
try {
53+
const value = stringify({
54+
id: 1,
55+
name: 'string',
56+
tag: 'otherString'
57+
})
58+
t.is(value, '{"id":1,"name":"string","tag":"otherString"}')
59+
} catch (e) {
60+
t.fail()
61+
}
62+
})

0 commit comments

Comments
 (0)