-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalues-of.spec.ts
41 lines (33 loc) · 1.16 KB
/
values-of.spec.ts
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
import { valuesOf } from './index.js'
import { forAll, record, unknown, string, array, oneOf, integer } from '../../random/index.js'
import { expect, it, expectTypeOf } from 'vitest'
it('valuesOf === Object.values', () => {
forAll(record(unknown()), (o) => {
expect(valuesOf(o)).toStrictEqual(Object.values(o))
})
})
it('valuesOf [xs] === Object.values', () => {
forAll(array(string()), (o) => {
expect(valuesOf(o)).toStrictEqual(Object.values(o))
})
})
it('valuesOf [1, 2, 3]', () => {
expect(valuesOf([1, 2, 3])).toMatchInlineSnapshot(`
[
1,
2,
3,
]
`)
})
it('valuesOf union object and array', () => {
forAll(oneOf(array(string()), record([integer(), integer()])), (o) => {
expect(valuesOf(o)).toStrictEqual(Object.values(o))
})
})
it('types', () => {
expectTypeOf(valuesOf({ foo: 'bar' })).toEqualTypeOf<'bar'[]>()
expectTypeOf(valuesOf<number[] | { foo: string }>({ foo: 'bar' })).toEqualTypeOf<number[] | string[]>()
expectTypeOf(valuesOf([1, 2, 3])).toEqualTypeOf<(1 | 2 | 3)[]>()
expectTypeOf(valuesOf([1, '2', 3])).toEqualTypeOf<(1 | '2' | 3)[]>()
})