Skip to content

Commit 06561f8

Browse files
authored
remove bad pattern from tests suites (#248)
1 parent 9effaab commit 06561f8

12 files changed

+304
-804
lines changed

test/allof.test.js

Lines changed: 48 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,16 @@ test('object with allOf and multiple schema on the allOf', (t) => {
5555
t.is(e.message, '"id" is required!')
5656
}
5757

58-
try {
59-
const value = stringify({
60-
id: 1,
61-
name: 'string'
62-
})
63-
t.is(value, '{"name":"string","id":1}')
64-
} catch (e) {
65-
t.fail()
66-
}
58+
t.is(stringify({
59+
id: 1,
60+
name: 'string'
61+
}), '{"name":"string","id":1}')
6762

68-
try {
69-
const value = stringify({
70-
id: 1,
71-
name: 'string',
72-
tag: 'otherString'
73-
})
74-
t.is(value, '{"name":"string","tag":"otherString","id":1}')
75-
} catch (e) {
76-
t.fail()
77-
}
63+
t.is(stringify({
64+
id: 1,
65+
name: 'string',
66+
tag: 'otherString'
67+
}), '{"name":"string","tag":"otherString","id":1}')
7868
})
7969

8070
test('object with allOf and one schema on the allOf', (t) => {
@@ -99,14 +89,10 @@ test('object with allOf and one schema on the allOf', (t) => {
9989
}
10090
const stringify = build(schema)
10191

102-
try {
103-
const value = stringify({
104-
id: 1
105-
})
106-
t.is(value, '{"id":1}')
107-
} catch (e) {
108-
t.fail()
109-
}
92+
const value = stringify({
93+
id: 1
94+
})
95+
t.is(value, '{"id":1}')
11096
})
11197

11298
test('object with allOf and no schema on the allOf', (t) => {
@@ -167,22 +153,14 @@ test('object with nested allOfs', (t) => {
167153
]
168154
}
169155

170-
try {
171-
const stringify = build(schema)
172-
try {
173-
const value = stringify({
174-
id1: 1,
175-
id2: 2,
176-
id3: 3,
177-
id4: 4 // extra prop shouldn't be in result
178-
})
179-
t.is(value, '{"id1":1,"id2":2,"id3":3}')
180-
} catch (e) {
181-
t.fail()
182-
}
183-
} catch (e) {
184-
t.fail()
185-
}
156+
const stringify = build(schema)
157+
const value = stringify({
158+
id1: 1,
159+
id2: 2,
160+
id3: 3,
161+
id4: 4 // extra prop shouldn't be in result
162+
})
163+
t.is(value, '{"id1":1,"id2":2,"id3":3}')
186164
})
187165

188166
test('object with $ref in allOf', (t) => {
@@ -208,20 +186,12 @@ test('object with $ref in allOf', (t) => {
208186
]
209187
}
210188

211-
try {
212-
const stringify = build(schema)
213-
try {
214-
const value = stringify({
215-
id1: 1,
216-
id2: 2 // extra prop shouldn't be in result
217-
})
218-
t.is(value, '{"id1":1}')
219-
} catch (e) {
220-
t.fail()
221-
}
222-
} catch (e) {
223-
t.fail()
224-
}
189+
const stringify = build(schema)
190+
const value = stringify({
191+
id1: 1,
192+
id2: 2 // extra prop shouldn't be in result
193+
})
194+
t.is(value, '{"id1":1}')
225195
})
226196

227197
test('object with $ref and other object in allOf', (t) => {
@@ -255,21 +225,13 @@ test('object with $ref and other object in allOf', (t) => {
255225
]
256226
}
257227

258-
try {
259-
const stringify = build(schema)
260-
try {
261-
const value = stringify({
262-
id1: 1,
263-
id2: 2,
264-
id3: 3 // extra prop shouldn't be in result
265-
})
266-
t.is(value, '{"id1":1,"id2":2}')
267-
} catch (e) {
268-
t.fail()
269-
}
270-
} catch (e) {
271-
t.fail()
272-
}
228+
const stringify = build(schema)
229+
const value = stringify({
230+
id1: 1,
231+
id2: 2,
232+
id3: 3 // extra prop shouldn't be in result
233+
})
234+
t.is(value, '{"id1":1,"id2":2}')
273235
})
274236

275237
test('object with multiple $refs in allOf', (t) => {
@@ -306,21 +268,13 @@ test('object with multiple $refs in allOf', (t) => {
306268
]
307269
}
308270

309-
try {
310-
const stringify = build(schema)
311-
try {
312-
const value = stringify({
313-
id1: 1,
314-
id2: 2,
315-
id3: 3 // extra prop shouldn't be in result
316-
})
317-
t.is(value, '{"id1":1,"id2":2}')
318-
} catch (e) {
319-
t.fail()
320-
}
321-
} catch (e) {
322-
t.fail()
323-
}
271+
const stringify = build(schema)
272+
const value = stringify({
273+
id1: 1,
274+
id2: 2,
275+
id3: 3 // extra prop shouldn't be in result
276+
})
277+
t.is(value, '{"id1":1,"id2":2}')
324278
})
325279

326280
test('object with external $refs in allOf', (t) => {
@@ -365,19 +319,11 @@ test('object with external $refs in allOf', (t) => {
365319
]
366320
}
367321

368-
try {
369-
const stringify = build(schema, { schema: externalSchema })
370-
try {
371-
const value = stringify({
372-
id1: 1,
373-
id2: 2,
374-
id3: 3 // extra prop shouldn't be in result
375-
})
376-
t.is(value, '{"id1":1,"id2":2}')
377-
} catch (e) {
378-
t.fail()
379-
}
380-
} catch (e) {
381-
t.fail()
382-
}
322+
const stringify = build(schema, { schema: externalSchema })
323+
const value = stringify({
324+
id1: 1,
325+
id2: 2,
326+
id3: 3 // extra prop shouldn't be in result
327+
})
328+
t.is(value, '{"id1":1,"id2":2}')
383329
})

test/any.test.js

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,27 @@ test('object with nested random property', (t) => {
1010
title: 'empty schema to allow any object',
1111
type: 'object',
1212
properties: {
13-
id: {
14-
type: 'number'
15-
},
13+
id: { type: 'number' },
1614
name: {}
1715
}
1816
}
1917
const stringify = build(schema)
2018

21-
try {
22-
const value = stringify({
23-
id: 1,
24-
name: 'string'
25-
})
26-
t.is(value, '{"id":1,"name":"string"}')
27-
} catch (e) {
28-
t.fail()
29-
}
30-
try {
31-
const value = stringify({
32-
id: 1,
33-
name: {
34-
first: 'name',
35-
last: 'last'
36-
}
37-
})
38-
t.is(value, '{"id":1,"name":{"first":"name","last":"last"}}')
39-
} catch (e) {
40-
t.fail()
41-
}
42-
try {
43-
const value = stringify({
44-
id: 1,
45-
name: null
46-
})
47-
t.is(value, '{"id":1,"name":null}')
48-
} catch (e) {
49-
t.fail()
50-
}
51-
try {
52-
const value = stringify({
53-
id: 1,
54-
name: ['first', 'last']
55-
})
56-
t.is(value, '{"id":1,"name":["first","last"]}')
57-
} catch (e) {
58-
t.fail()
59-
}
19+
t.is(stringify({
20+
id: 1, name: 'string'
21+
}), '{"id":1,"name":"string"}')
22+
23+
t.is(stringify({
24+
id: 1, name: { first: 'name', last: 'last' }
25+
}), '{"id":1,"name":{"first":"name","last":"last"}}')
26+
27+
t.is(stringify({
28+
id: 1, name: null
29+
}), '{"id":1,"name":null}')
30+
31+
t.is(stringify({
32+
id: 1, name: ['first', 'last']
33+
}), '{"id":1,"name":["first","last"]}')
6034
})
6135

6236
test('array with random items', (t) => {
@@ -65,15 +39,10 @@ test('array with random items', (t) => {
6539
const schema = {
6640
title: 'empty schema to allow any object',
6741
type: 'array',
68-
items: {
69-
}
42+
items: {}
7043
}
7144
const stringify = build(schema)
7245

73-
try {
74-
const value = stringify([1, 'string', null])
75-
t.is(value, '[1,"string",null]')
76-
} catch (e) {
77-
t.fail()
78-
}
46+
const value = stringify([1, 'string', null])
47+
t.is(value, '[1,"string",null]')
7948
})

0 commit comments

Comments
 (0)