-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathexclusive-between.spec.ts
More file actions
155 lines (137 loc) · 4.43 KB
/
exclusive-between.spec.ts
File metadata and controls
155 lines (137 loc) · 4.43 KB
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
import { AbstractControlState, box, unbox, validate } from 'ngrx-forms';
import { exclusiveBetween } from './exclusive-between';
describe(exclusiveBetween.name, () => {
it('should throw for null min parameter', () => {
expect(() => exclusiveBetween(null as any, 100)).toThrow();
});
it('should throw for undefined min parameter', () => {
expect(() => exclusiveBetween(undefined as any, 100)).toThrow();
});
it('should throw for null max parameter', () => {
expect(() => exclusiveBetween(0, null as any)).toThrow();
});
it('should throw for undefined max parameter', () => {
expect(() => exclusiveBetween(0, undefined as any)).toThrow();
});
it('should not return an error for null', () => {
expect(exclusiveBetween(0, 100)(null)).toEqual({});
});
it('should not return an error for undefined', () => {
expect(exclusiveBetween(0, 100)(undefined)).toEqual({});
});
it('should not return an error for non-numeric value', () => {
expect(exclusiveBetween(0, 100)('string' as any)).toEqual({});
});
it('should not return an error if value is greater than min and less than max', () => {
expect(exclusiveBetween(0, 100)(50)).toEqual({});
});
it('should return errors with min, max and actual properties if less than min', () => {
const min = 0;
const max = 100;
const actual = -1;
expect(exclusiveBetween(0, 100)(actual)).toEqual({
exclusiveBetween: {
min,
max,
actual,
},
});
});
it('should return an errors with min, max and actual properties if equal to min', () => {
const min = 0;
const max = 100;
const actual = 0;
expect(exclusiveBetween(0, 100)(actual)).toEqual({
exclusiveBetween: {
min,
max,
actual,
},
});
});
it('should return errors with min, max and actual properties if greater than max', () => {
const min = 0;
const max = 100;
const actual = 101;
expect(exclusiveBetween(0, 100)(actual)).toEqual({
exclusiveBetween: {
min,
max,
actual,
},
});
});
it('should return an errors with min, max and actual properties if equal to max', () => {
const min = 0;
const max = 100;
const actual = 100;
expect(exclusiveBetween(0, 100)(actual)).toEqual({
exclusiveBetween: {
min,
max,
actual,
},
});
});
it('should not return an error if boxed value is greater than min and less than max', () => {
expect(exclusiveBetween(0, 100)(box(50))).toEqual({});
});
it('should return errors with min, max and actual properties for boxed values if less than min', () => {
const min = 0;
const max = 100;
const actual = box(-1);
expect(exclusiveBetween(min, max)(actual)).toEqual({
exclusiveBetween: {
min,
max,
actual: unbox(actual),
},
});
});
it('should return an errors with min, max and actual properties for boxed values if equal to min', () => {
const min = 0;
const max = 100;
const actual = box(0);
expect(exclusiveBetween(0, 100)(actual)).toEqual({
exclusiveBetween: {
min,
max,
actual: unbox(actual),
},
});
});
it('should return errors with min, max and actual properties for boxed values if greater than max', () => {
const min = 0;
const max = 100;
const actual = box(101);
expect(exclusiveBetween(min, max)(actual)).toEqual({
exclusiveBetween: {
min,
max,
actual: unbox(actual),
},
});
});
it('should return an errors with min, max and actual properties for boxed values if equal to max', () => {
const min = 0;
const max = 100;
const actual = box(100);
expect(exclusiveBetween(0, 100)(actual)).toEqual({
exclusiveBetween: {
min,
max,
actual: unbox(actual),
},
});
});
it('should properly infer value type when used with validate update function', () => {
// this code is never meant to be executed, it should just pass the type checker
if (1 !== 1) {
// tslint:disable-next-line:no-non-null-assertion
const state: AbstractControlState<number> = undefined!;
const v = validate(state, exclusiveBetween(0, 100));
const v2: number = v.value;
console.log(v2);
}
});
});