deno.land / x / rambda@v9.1.1 / source / type.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { type as typeRamda } from 'ramda'
import { type } from './type.js'
test('with buffer', () => { expect(type(new Buffer.from('foo'))).toBe('Uint8Array')})
test('with array buffer', () => { expect(type(new ArrayBuffer(8))).toBe('ArrayBuffer')})
test('with big int', () => { expect(type(BigInt(9007199254740991))).toBe('BigInt')})
test('with generators', () => { function* generator(){ yield 1 yield 2 yield 3 }
const gen = generator() expect(type(generator)).toBe('GeneratorFunction') expect(type(gen)).toBe('Generator')})
test('with Date', () => { const date = new Date('December 17, 1995 03:24:00') expect(type(date)).toBe('Date')})
test('with infinity', () => { expect(type(Infinity)).toBe('Number')})
test('with weak map', () => { expect(type(new WeakMap())).toBe('WeakMap')})
test('with map', () => { expect(type(new Map())).toBe('Map')})
test('with symbol', () => { expect(type(Symbol())).toBe('Symbol')})
test('with simple promise', () => { expect(type(Promise.resolve(1))).toBe('Promise')})
test('with new Boolean', () => { expect(type(new Boolean(true))).toBe('Boolean')})
test('with new String', () => { expect(type(new String('I am a String object'))).toBe('String')})
test('with new Number', () => { expect(type(new Number(1))).toBe('Number')})
test('with error', () => { expect(type(Error('foo'))).toBe('Error') expect(typeRamda(Error('foo'))).toBe('Error')})
test('with error - wrong @types/ramda test', () => { // @types/ramda expect the result to be 'Error' but it is not class ExtendedError extends Error{} expect(type(ExtendedError)).toBe('Function') expect(typeRamda(ExtendedError)).toBe('Function')})
test('with new promise', () => { const delay = ms => new Promise(resolve => { setTimeout(() => { resolve(ms + 110) }, ms) })
expect(type(delay(10))).toBe('Promise')})
test('async function', () => { expect(type(async () => {})).toBe('Promise')})
test('async arrow', () => { const asyncArrow = async () => {} expect(type(asyncArrow)).toBe('Promise')})
test('function', () => { const fn1 = () => {} const fn2 = function (){}
function fn3(){}
;[ () => {}, fn1, fn2, fn3 ].map(val => { expect(type(val)).toBe('Function') })})
test('object', () => { expect(type({})).toBe('Object')})
test('number', () => { expect(type(1)).toBe('Number')})
test('boolean', () => { expect(type(false)).toBe('Boolean')})
test('string', () => { expect(type('foo')).toBe('String')})
test('null', () => { expect(type(null)).toBe('Null')})
test('array', () => { expect(type([])).toBe('Array') expect(type([ 1, 2, 3 ])).toBe('Array')})
test('regex', () => { expect(type(/\s/g)).toBe('RegExp')})
test('undefined', () => { expect(type(undefined)).toBe('Undefined')})
test('not a number', () => { expect(type(Number('s'))).toBe('NaN')})
test('set', () => { const exampleSet = new Set([ 1, 2, 3 ]) expect(type(exampleSet)).toBe('Set') expect(typeRamda(exampleSet)).toBe('Set')})
test('function inside object 1', () => { const obj = { f(){ return 4 }, }
expect(type(obj.f)).toBe('Function') expect(typeRamda(obj.f)).toBe('Function')})
test('function inside object 2', () => { const name = 'f' const obj = { [ name ](){ return 4 }, } expect(type(obj.f)).toBe('Function') expect(typeRamda(obj.f)).toBe('Function')})
rambda

Version Info

Tagged at
2 months ago