-
Notifications
You must be signed in to change notification settings - Fork 86
/
add.spec.js
53 lines (48 loc) · 1.14 KB
/
add.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {add} from './add'
import {add as addRamda} from 'ramda'
import {compareCombinations} from './_internals/testUtils'
test('with number', () => {
expect(add(2, 3)).toEqual(5)
expect(add(7)(10)).toEqual(17)
})
test('string is bad input', () => {
expect(add('foo', 'bar')).toBeNaN()
})
test('ramda specs', () => {
expect(add('1', '2')).toEqual(3)
expect(add(1, '2')).toEqual(3)
expect(add(true, false)).toEqual(1)
expect(add(null, null)).toEqual(0)
expect(add(undefined, undefined)).toEqual(NaN)
expect(add(new Date(1), new Date(2))).toEqual(3)
})
const possibleInputs = [
/foo/,
'foo',
true,
3,
NaN,
4,
[],
Promise.resolve(1),
]
describe('brute force', () => {
compareCombinations({
fn: add,
fnRamda: addRamda,
firstInput: possibleInputs,
secondInput: possibleInputs,
callback: errorsCounters => {
expect(errorsCounters).toMatchInlineSnapshot(`
Object {
"ERRORS_MESSAGE_MISMATCH": 0,
"ERRORS_TYPE_MISMATCH": 0,
"RESULTS_MISMATCH": 0,
"SHOULD_NOT_THROW": 0,
"SHOULD_THROW": 0,
"TOTAL_TESTS": 64,
}
`)
},
})
})