-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallInvalid.js
41 lines (35 loc) · 1023 Bytes
/
allInvalid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Joi from 'joi'
/**
* For all supplied configs (array of objects), check that they are invalid given a schema.
*/
export default (configs, schema) => {
// Set throw to true for debugging reasons
configs.forEach(({ input: invalidConfig, error: expectedError, throwError = false }, n) => {
it(`invalid #${n} should be invalid`, () => {
if (!invalidConfig) {
throw new Error('Pass data as `input` property')
}
let result
try {
Joi.assert(invalidConfig, schema)
} catch (e) {
result = e
}
if (throwError) {
throw result
}
assert(result)
if (expectedError) {
if (expectedError.path) {
assert(result.details[0].path === expectedError.path)
}
if (expectedError.type) {
assert(result.details[0].type === expectedError.type)
}
if (expectedError.message) {
assert(result.details[0].message === expectedError.message)
}
}
})
})
}