-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.spec.js
37 lines (32 loc) · 1.03 KB
/
error.spec.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
const assert = require('assert')
const wavematch = require('../dist/wavematch.cjs.development.js')
const { accept, reject, eq } = require('./shared.js')
const allErrorTypes = [
EvalError,
RangeError,
ReferenceError,
SyntaxError,
TypeError,
URIError,
Error,
]
describe('wavematch Error type specification', () => {
it('should allow `Error` as pattern to accept all other standard Error types', () => {
const matchStandardError = standardErrorType =>
wavematch(standardErrorType)((e = Error) => accept, _ => reject)
allErrorTypes.forEach(errorType => {
eq(matchStandardError(errorType()), accept)
})
})
// now just gotta write tests for all of the other Error subtypes
// RangeError, ReferenceError, TypeError, URIError, EvalError ...
it('should accept specific Error subtypes via that constructor', () => {
let match = wavematch(SyntaxError())(
(e = RangeError) => reject,
(e = SyntaxError) => accept,
(e = URIError) => reject,
_ => reject,
)
eq(match, accept)
})
})