-
Notifications
You must be signed in to change notification settings - Fork 0
/
isTruthy.test.ts
129 lines (108 loc) · 3.57 KB
/
isTruthy.test.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
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
/**
* ❌: The expectation should be equal to false
* ✅: The expectation should be equal to true
* ➖: The expectation can be equal to true or false
*/
import { describe, it, test, expect } from 'vitest';
import values from '../__Fixtures/values.js';
import isTruthy from '../../src/isTruthy.js';
const KEY = 'truthy';
describe('is/isTruthy', () => {
it(`❌ nil !== ${KEY}`, () => {
values.nil.forEach((value) => {
expect(isTruthy(value)).toEqual(false);
});
});
it(`➖ booleans !== || === ${KEY}`, () => {
values.booleans.forEach((value) => {
expect(isTruthy(value)).toEqual(value === true);
});
});
it(`➖ integers !== || === ${KEY}`, () => {
values.integers.forEach((value) => {
expect(isTruthy(value)).toEqual(![0, -0].includes(value));
});
});
it(`✅ floats === ${KEY}`, () => {
values.floats.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`➖ numbers !== || === ${KEY}`, () => {
values.numbers.forEach((value) => {
expect(isTruthy(value)).toEqual(![0, -0, NaN].includes(value));
});
});
it(`➖ bigInts !== || === ${KEY}`, () => {
values.bigInts.forEach((value) => {
expect(isTruthy(value)).toEqual(value !== 0n);
});
});
it(`➖ strings !== || === ${KEY}`, () => {
values.strings.forEach((value) => {
expect(isTruthy(value)).toEqual(value !== '');
});
});
it(`✅ symbols === ${KEY}`, () => {
values.symbols.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`✅ arrays === ${KEY}`, () => {
values.arrays.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`✅ DOM elements === ${KEY}`, () => {
values.elements.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`✅ DOM nodeLists === ${KEY}`, () => {
values.nodeLists.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`✅ DOM alternative contexts === ${KEY}`, () => {
values.alternativeDOMs.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`✅ functions === ${KEY}`, () => {
values.functions.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`✅ classes === ${KEY}`, () => {
values.classes.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`✅ object constructors === ${KEY}`, () => {
values.constructors.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`➖ invoked object constructors !== || === ${KEY}`, () => {
values.invokedConstructors.forEach((value) => {
expect(isTruthy(value)).toEqual(!!value);
});
});
it(`✅ object instances === ${KEY}`, () => {
values.instances.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
it(`✅ objects === ${KEY}`, () => {
values.objects.forEach((value) => {
expect(isTruthy(value)).toEqual(true);
});
});
Object.entries(values).forEach(([key, items]) => {
test(`isTruthy() === any truthy value | [${key}]`, () => {
items.forEach((value) => {
expect(isTruthy(value)).toEqual(!!value);
});
});
});
});