-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
35 lines (30 loc) · 985 Bytes
/
test.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
'use strict'
const { AssertionError } = require('assert')
const test = require('ava')
const never = require('.')
const ShimmedAssertionError = require('./AssertionError.native')
test('throws when called', t => {
t.throws(never, { instanceOf: AssertionError })
})
test('errors have a default message', t => {
const error = t.throws(never)
t.snapshot(error.message)
})
test('error message can be customized', t => {
const message = 'This is a custom message'
t.throws(() => never('This is a custom message'), { message })
})
test('never() is not in the error stack', t => {
const wrapper = () => never()
const error = t.throws(wrapper)
t.regex(error.stack.split('\n')[1], /wrapper/)
})
test('the shimmed AssertionError can be constructed', t => {
const error = t.throws(() => {
throw new ShimmedAssertionError({ message: 'Error message' })
}, {
instanceOf: ShimmedAssertionError,
message: 'Error message'
})
t.is(error.name, 'AssertionError')
})