deno.land / x / rambda@v9.1.1 / source / ok.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { ok, schemaToString } from './ok.js'
test('happy', () => { expect(() => { ok( 1, 'foo', {} )( 'number', 'string', 'object' ) }).not.toThrow()})
test('when validation fails', () => { expect(() => ok( 1, 'foo', {} )( 'number', 'string', 'string' )) .toThrowErrorMatchingInlineSnapshot(` "Failed R.ok - reason: {"input":{},"schema":"string"} all inputs: [1,"foo",{}] all schemas: ["number","string","string"]" `)})
test('schema in error message', () => { const result = schemaToString({ _a : [ Number ], a : Number, b : x => x > 2, c : [ 'foo', 'bar' ], d : [ { a : String } ], e : 'boolean', f : Array, h : Object, })
expect(result).toMatchInlineSnapshot(` { "_a": "Array", "a": "number", "b": "Function", "c": "Array", "d": "Array", "e": "String", "f": "array", "h": "object", } `)})
test('error contains schema', () => { try { ok( 1, 'foo', {} )( { a : Number }, String, String ) expect(false).toBeTrue() } catch (e){ expect(e.message.startsWith('Failed R.ok -')).toBeTruthy() expect(e).toBeInstanceOf(Error) }})
test('when not throws with single schema', () => { expect(() => ok( 1, 2, 3 )('number')).not.toThrow()})
test('when throws with single schema', () => { expect(() => ok( 1, 2, '3' )('number')).toThrowErrorMatchingInlineSnapshot(` "Failed R.ok - reason: {"input":"3","schema":"number"} all inputs: [1,2,"3"] all schemas: ["number"]" `)})
test('when throws with single input', () => { expect(() => ok('3')('number')).toThrowErrorMatchingInlineSnapshot('"Failed R.ok - {"input":"3","schema":"number"}"')})
rambda

Version Info

Tagged at
2 months ago