/
Expected.test.js
53 lines (50 loc) · 1.46 KB
/
Expected.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Exception from './Exception'
import Expected from './Expected'
import anyToStringTag from '../util/anyToStringTag'
describe('js:Expected', () => {
describe('constructor', () => {
test('correctly constructs the Type instance', () => {
const instance = new Expected({
data: {},
exceptionToError: () => {},
expectation: 'foo'
})
expect(instance).toBeInstanceOf(Expected)
expect(instance).toMatchObject({
data: {},
expectation: 'foo'
})
})
})
describe('Symbol.toStringTag', () => {
test('Returns back a custom StringTag', () => {
const instance = new Expected({
data: {},
exceptionToError: () => {},
expectation: 'foo'
})
expect(anyToStringTag(instance)).toBe('Expected')
})
})
describe('toError', () => {
test('Returns an Error from the given exception', () => {
const error = new Error('foo')
const exceptionToError = jest.fn(() => error)
const expected = new Expected({
data: {},
exceptionToError,
expectation: 'foo'
})
const source = function () {}
const target = {
index: 0,
type: 'Argument',
value: 'test'
}
const exception = new Exception({ expected, source, target })
const result = expected.toError(exception)
expect(result).toBe(error)
expect(exceptionToError).toHaveBeenCalledWith(exception, expected)
})
})
})