@serenity-js/assertions 3.0.0-rc.21 → 3.0.0-rc.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -143
- package/lib/expectations/index.d.ts +1 -0
- package/lib/expectations/index.js +1 -0
- package/lib/expectations/index.js.map +1 -1
- package/lib/expectations/isCloseTo.d.ts +17 -0
- package/lib/expectations/isCloseTo.js +51 -0
- package/lib/expectations/isCloseTo.js.map +1 -0
- package/package.json +4 -4
- package/src/expectations/index.ts +1 -0
- package/src/expectations/isCloseTo.ts +60 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,26 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
# [3.0.0-rc.
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @serenity-js/assertions
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [3.0.0-rc.20](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.19...v3.0.0-rc.20) (2022-07-11)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### Features
|
|
18
|
-
|
|
19
|
-
* **core:** interactions to Wait.for and Wait.until are now browser-independent ([d115142](https://github.com/serenity-js/serenity-js/commit/d1151427bed96c1ebd0d1dcc4159c6aeedc605de)), closes [#1035](https://github.com/serenity-js/serenity-js/issues/1035) [#1236](https://github.com/serenity-js/serenity-js/issues/1236)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# [3.0.0-rc.19](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.18...v3.0.0-rc.19) (2022-06-11)
|
|
6
|
+
# [3.0.0-rc.24](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.23...v3.0.0-rc.24) (2022-07-23)
|
|
26
7
|
|
|
27
8
|
**Note:** Version bump only for package @serenity-js/assertions
|
|
28
9
|
|
|
@@ -30,118 +11,52 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
30
11
|
|
|
31
12
|
|
|
32
13
|
|
|
33
|
-
# [3.0.0-rc.
|
|
14
|
+
# [3.0.0-rc.23](https://github.com/serenity-js/serenity-js/compare/v2.33.10...v3.0.0-rc.23) (2022-07-19)
|
|
34
15
|
|
|
35
16
|
|
|
36
17
|
### Bug Fixes
|
|
37
18
|
|
|
38
|
-
* **
|
|
39
|
-
* **deps:** updated tiny-types to 1.18.2 ([83a651c](https://github.com/serenity-js/serenity-js/commit/83a651c4c2f3f8dbaabcdacba94c720efdff45dd))
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
# [3.0.0-rc.17](https://github.com/serenity-js/serenity-js/compare/v2.33.8...v3.0.0-rc.17) (2022-06-02)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
# [3.0.0-rc.16](https://github.com/serenity-js/serenity-js/compare/v2.33.6...v3.0.0-rc.16) (2022-04-15)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
# [3.0.0-rc.15](https://github.com/serenity-js/serenity-js/compare/v2.33.5...v3.0.0-rc.15) (2022-04-10)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
# [3.0.0-rc.14](https://github.com/serenity-js/serenity-js/compare/v2.33.3...v3.0.0-rc.14) (2022-03-28)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# [3.0.0-rc.13](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.12...v3.0.0-rc.13) (2022-03-02)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
# [3.0.0-rc.12](https://github.com/serenity-js/serenity-js/compare/v2.33.2...v3.0.0-rc.12) (2022-02-23)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
# [3.0.0-rc.11](https://github.com/serenity-js/serenity-js/compare/v2.33.1...v3.0.0-rc.11) (2022-02-13)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# [3.0.0-rc.10](https://github.com/serenity-js/serenity-js/compare/v2.33.0...v3.0.0-rc.10) (2022-02-03)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
# [3.0.0-rc.9](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.8...v3.0.0-rc.9) (2022-02-01)
|
|
19
|
+
* **node:** support for Node 18 ([73212bc](https://github.com/serenity-js/serenity-js/commit/73212bc9deb1998d871b0720a6b437687b3ceddc)), closes [#1243](https://github.com/serenity-js/serenity-js/issues/1243)
|
|
76
20
|
|
|
77
21
|
|
|
78
22
|
|
|
79
|
-
# [3.0.0-rc.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
# [3.0.0-rc.7](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.6...v3.0.0-rc.7) (2022-01-28)
|
|
23
|
+
# [3.0.0-rc.22](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.21...v3.0.0-rc.22) (2022-07-15)
|
|
84
24
|
|
|
85
25
|
|
|
86
26
|
### Features
|
|
87
27
|
|
|
88
|
-
* **assertions:**
|
|
89
|
-
* **core:** replaced `Adapter` with `QuestionAdapter` and introduced `Optional` ([8d84ad3](https://github.com/serenity-js/serenity-js/commit/8d84ad3863e3c726533d0f21934fb1e2fa8b3022)), closes [#1103](https://github.com/serenity-js/serenity-js/issues/1103)
|
|
90
|
-
* **core:** support for Optional chaining, expectation isPresent, refactored Expectations ([1841ee5](https://github.com/serenity-js/serenity-js/commit/1841ee5fc48cfa403ddc53358f75764d9a010c21)), closes [#1099](https://github.com/serenity-js/serenity-js/issues/1099) [#1099](https://github.com/serenity-js/serenity-js/issues/1099) [#1103](https://github.com/serenity-js/serenity-js/issues/1103)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
# [3.0.0-rc.6](https://github.com/serenity-js/serenity-js/compare/v2.32.7...v3.0.0-rc.6) (2022-01-10)
|
|
28
|
+
* **assertions:** isCloseTo(expected, tolerance) ([bb0e935](https://github.com/serenity-js/serenity-js/commit/bb0e935e197b195da598ccbec6c6cf7704dd875b))
|
|
95
29
|
|
|
96
30
|
|
|
97
31
|
|
|
98
|
-
# [3.0.0-rc.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# [3.0.0-rc.4](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.3...v3.0.0-rc.4) (2021-12-30)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
# [3.0.0-rc.3](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.2...v3.0.0-rc.3) (2021-12-29)
|
|
32
|
+
# [3.0.0-rc.21](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.20...v3.0.0-rc.21) (2022-07-11)
|
|
107
33
|
|
|
108
34
|
|
|
109
|
-
### Bug Fixes
|
|
110
35
|
|
|
111
|
-
|
|
36
|
+
# [3.0.0-rc.20](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.19...v3.0.0-rc.20) (2022-07-11)
|
|
112
37
|
|
|
113
38
|
|
|
39
|
+
### Features
|
|
114
40
|
|
|
115
|
-
|
|
41
|
+
* **core:** interactions to Wait.for and Wait.until are now browser-independent ([d115142](https://github.com/serenity-js/serenity-js/commit/d1151427bed96c1ebd0d1dcc4159c6aeedc605de)), closes [#1035](https://github.com/serenity-js/serenity-js/issues/1035) [#1236](https://github.com/serenity-js/serenity-js/issues/1236)
|
|
116
42
|
|
|
117
43
|
|
|
118
44
|
|
|
119
|
-
# [3.0.0-rc.
|
|
45
|
+
# [3.0.0-rc.19](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.18...v3.0.0-rc.19) (2022-06-11)
|
|
120
46
|
|
|
121
47
|
|
|
122
48
|
|
|
123
|
-
# [3.0.0-rc.
|
|
49
|
+
# [3.0.0-rc.18](https://github.com/serenity-js/serenity-js/compare/v2.33.9...v3.0.0-rc.18) (2022-06-06)
|
|
124
50
|
|
|
125
51
|
|
|
126
52
|
### Bug Fixes
|
|
127
53
|
|
|
128
|
-
* **
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
### BREAKING CHANGES
|
|
132
|
-
|
|
133
|
-
* **core:** Introduced @serenity-js/web - a shared library for Serenity/JS Web integration
|
|
134
|
-
modules such as @serenity-js/protractor and @serenity-js/webdriverio. Dropped support for Node 12.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
# [3.0.0-rc.17](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.16...v3.0.0-rc.17) (2022-06-02)
|
|
54
|
+
* **deps:** updated tiny-types ([f1951cf](https://github.com/serenity-js/serenity-js/commit/f1951cf753df3807b5778d116f8e8bc3f24830a7))
|
|
55
|
+
* **deps:** updated tiny-types to 1.18.2 ([83a651c](https://github.com/serenity-js/serenity-js/commit/83a651c4c2f3f8dbaabcdacba94c720efdff45dd))
|
|
141
56
|
|
|
142
|
-
**Note:** Version bump only for package @serenity-js/assertions
|
|
143
57
|
|
|
144
58
|
|
|
59
|
+
# [3.0.0-rc.17](https://github.com/serenity-js/serenity-js/compare/v2.33.8...v3.0.0-rc.17) (2022-06-02)
|
|
145
60
|
|
|
146
61
|
|
|
147
62
|
|
|
@@ -238,92 +153,63 @@ modules such as @serenity-js/protractor and @serenity-js/webdriverio. Dropped su
|
|
|
238
153
|
|
|
239
154
|
|
|
240
155
|
|
|
241
|
-
# [3.0.0-rc.
|
|
156
|
+
# [3.0.0-rc.22](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.21...v3.0.0-rc.22) (2022-07-15)
|
|
242
157
|
|
|
243
158
|
|
|
159
|
+
### Features
|
|
244
160
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
# [3.0.0-rc.13](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.12...v3.0.0-rc.13) (2022-03-02)
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
# [3.0.0-rc.12](https://github.com/serenity-js/serenity-js/compare/v2.33.2...v3.0.0-rc.12) (2022-02-23)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
# [3.0.0-rc.11](https://github.com/serenity-js/serenity-js/compare/v2.33.1...v3.0.0-rc.11) (2022-02-13)
|
|
258
|
-
|
|
161
|
+
* **assertions:** isCloseTo(expected, tolerance) ([bb0e935](https://github.com/serenity-js/serenity-js/commit/bb0e935e197b195da598ccbec6c6cf7704dd875b))
|
|
259
162
|
|
|
260
163
|
|
|
261
|
-
# [3.0.0-rc.10](https://github.com/serenity-js/serenity-js/compare/v2.33.0...v3.0.0-rc.10) (2022-02-03)
|
|
262
164
|
|
|
263
165
|
|
|
264
166
|
|
|
265
|
-
# [3.0.0-rc.
|
|
167
|
+
# [3.0.0-rc.21](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.20...v3.0.0-rc.21) (2022-07-11)
|
|
266
168
|
|
|
169
|
+
**Note:** Version bump only for package @serenity-js/assertions
|
|
267
170
|
|
|
268
171
|
|
|
269
|
-
# [3.0.0-rc.8](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.7...v3.0.0-rc.8) (2022-01-28)
|
|
270
172
|
|
|
271
173
|
|
|
272
174
|
|
|
273
|
-
# [3.0.0-rc.
|
|
175
|
+
# [3.0.0-rc.20](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.19...v3.0.0-rc.20) (2022-07-11)
|
|
274
176
|
|
|
275
177
|
|
|
276
178
|
### Features
|
|
277
179
|
|
|
278
|
-
* **
|
|
279
|
-
* **core:** replaced `Adapter` with `QuestionAdapter` and introduced `Optional` ([8d84ad3](https://github.com/serenity-js/serenity-js/commit/8d84ad3863e3c726533d0f21934fb1e2fa8b3022)), closes [#1103](https://github.com/serenity-js/serenity-js/issues/1103)
|
|
280
|
-
* **core:** support for Optional chaining, expectation isPresent, refactored Expectations ([1841ee5](https://github.com/serenity-js/serenity-js/commit/1841ee5fc48cfa403ddc53358f75764d9a010c21)), closes [#1099](https://github.com/serenity-js/serenity-js/issues/1099) [#1099](https://github.com/serenity-js/serenity-js/issues/1099) [#1103](https://github.com/serenity-js/serenity-js/issues/1103)
|
|
180
|
+
* **core:** interactions to Wait.for and Wait.until are now browser-independent ([d115142](https://github.com/serenity-js/serenity-js/commit/d1151427bed96c1ebd0d1dcc4159c6aeedc605de)), closes [#1035](https://github.com/serenity-js/serenity-js/issues/1035) [#1236](https://github.com/serenity-js/serenity-js/issues/1236)
|
|
281
181
|
|
|
282
182
|
|
|
283
183
|
|
|
284
|
-
# [3.0.0-rc.6](https://github.com/serenity-js/serenity-js/compare/v2.32.7...v3.0.0-rc.6) (2022-01-10)
|
|
285
184
|
|
|
286
185
|
|
|
186
|
+
# [3.0.0-rc.19](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.18...v3.0.0-rc.19) (2022-06-11)
|
|
287
187
|
|
|
288
|
-
|
|
289
|
-
|
|
188
|
+
**Note:** Version bump only for package @serenity-js/assertions
|
|
290
189
|
|
|
291
190
|
|
|
292
|
-
# [3.0.0-rc.4](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.3...v3.0.0-rc.4) (2021-12-30)
|
|
293
191
|
|
|
294
192
|
|
|
295
193
|
|
|
296
|
-
# [3.0.0-rc.
|
|
194
|
+
# [3.0.0-rc.18](https://github.com/serenity-js/serenity-js/compare/v2.33.9...v3.0.0-rc.18) (2022-06-06)
|
|
297
195
|
|
|
298
196
|
|
|
299
197
|
### Bug Fixes
|
|
300
198
|
|
|
301
|
-
* **deps:** updated tiny-types
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
# [3.0.0-rc.2](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.1...v3.0.0-rc.2) (2021-12-09)
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
# [3.0.0-rc.1](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.0...v3.0.0-rc.1) (2021-12-09)
|
|
199
|
+
* **deps:** updated tiny-types ([f1951cf](https://github.com/serenity-js/serenity-js/commit/f1951cf753df3807b5778d116f8e8bc3f24830a7))
|
|
200
|
+
* **deps:** updated tiny-types to 1.18.2 ([83a651c](https://github.com/serenity-js/serenity-js/commit/83a651c4c2f3f8dbaabcdacba94c720efdff45dd))
|
|
310
201
|
|
|
311
202
|
|
|
312
203
|
|
|
313
|
-
# [3.0.0-rc.
|
|
204
|
+
# [3.0.0-rc.17](https://github.com/serenity-js/serenity-js/compare/v2.33.8...v3.0.0-rc.17) (2022-06-02)
|
|
314
205
|
|
|
315
206
|
|
|
316
|
-
### Bug Fixes
|
|
317
207
|
|
|
318
|
-
|
|
208
|
+
# [3.0.0-rc.16](https://github.com/serenity-js/serenity-js/compare/v2.33.6...v3.0.0-rc.16) (2022-04-15)
|
|
319
209
|
|
|
320
210
|
|
|
321
|
-
### BREAKING CHANGES
|
|
322
|
-
|
|
323
|
-
* **core:** Introduced @serenity-js/web - a shared library for Serenity/JS Web integration
|
|
324
|
-
modules such as @serenity-js/protractor and @serenity-js/webdriverio. Dropped support for Node 12.
|
|
325
|
-
|
|
326
211
|
|
|
212
|
+
# [3.0.0-rc.15](https://github.com/serenity-js/serenity-js/compare/v2.33.5...v3.0.0-rc.15) (2022-04-10)
|
|
327
213
|
|
|
328
214
|
|
|
329
215
|
|
|
@@ -408,6 +294,14 @@ modules such as @serenity-js/protractor and @serenity-js/webdriverio. Dropped su
|
|
|
408
294
|
* **core:** Introduced @serenity-js/web - a shared library for Serenity/JS Web integration
|
|
409
295
|
modules such as @serenity-js/protractor and @serenity-js/webdriverio. Dropped support for Node 12.
|
|
410
296
|
|
|
297
|
+
## [2.33.10](https://github.com/serenity-js/serenity-js/compare/v2.33.9...v2.33.10) (2022-07-19)
|
|
298
|
+
|
|
299
|
+
**Note:** Version bump only for package @serenity-js/assertions
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
411
305
|
## [2.33.9](https://github.com/serenity-js/serenity-js/compare/v2.33.8...v2.33.9) (2022-06-02)
|
|
412
306
|
|
|
413
307
|
**Note:** Version bump only for package @serenity-js/assertions
|
|
@@ -23,6 +23,7 @@ __exportStar(require("./equals"), exports);
|
|
|
23
23
|
__exportStar(require("./includes"), exports);
|
|
24
24
|
__exportStar(require("./isAfter"), exports);
|
|
25
25
|
__exportStar(require("./isBefore"), exports);
|
|
26
|
+
__exportStar(require("./isCloseTo"), exports);
|
|
26
27
|
__exportStar(require("./isFalse"), exports);
|
|
27
28
|
__exportStar(require("./isGreaterThan"), exports);
|
|
28
29
|
__exportStar(require("./isLessThan"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/expectations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,4CAA0B;AAC1B,8DAA4C;AAC5C,8DAA4C;AAC5C,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B;AAC1B,kDAAgC;AAChC,+CAA6B;AAC7B,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B;AAC1B,wCAAsB;AACtB,uCAAqB;AACrB,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/expectations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,4CAA0B;AAC1B,8DAA4C;AAC5C,8DAA4C;AAC5C,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,6CAA2B;AAC3B,8CAA4B;AAC5B,4CAA0B;AAC1B,kDAAgC;AAChC,+CAA6B;AAC7B,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B;AAC1B,wCAAsB;AACtB,uCAAqB;AACrB,+CAA6B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Answerable, Expectation } from '@serenity-js/core';
|
|
2
|
+
/**
|
|
3
|
+
* @desc
|
|
4
|
+
* Expectation that the actual value is within a given ± absolute tolerance range of the expected value.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
8
|
+
* import { Ensure, isCloseTo } from '@serenity-js/assertions'
|
|
9
|
+
*
|
|
10
|
+
* await actorCalled('Iris').attemptsTo(
|
|
11
|
+
* Ensure.that(10.123, isCloseTo(10, 0.2))
|
|
12
|
+
* )
|
|
13
|
+
*
|
|
14
|
+
* @param {Answerable<number>} expected
|
|
15
|
+
* @param {Answerable<number>} [absoluteTolerance=1e-9]
|
|
16
|
+
*/
|
|
17
|
+
export declare function isCloseTo(expected: Answerable<number>, absoluteTolerance?: Answerable<number>): Expectation<number>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCloseTo = void 0;
|
|
4
|
+
const core_1 = require("@serenity-js/core");
|
|
5
|
+
/**
|
|
6
|
+
* @desc
|
|
7
|
+
* Expectation that the actual value is within a given ± absolute tolerance range of the expected value.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
11
|
+
* import { Ensure, isCloseTo } from '@serenity-js/assertions'
|
|
12
|
+
*
|
|
13
|
+
* await actorCalled('Iris').attemptsTo(
|
|
14
|
+
* Ensure.that(10.123, isCloseTo(10, 0.2))
|
|
15
|
+
* )
|
|
16
|
+
*
|
|
17
|
+
* @param {Answerable<number>} expected
|
|
18
|
+
* @param {Answerable<number>} [absoluteTolerance=1e-9]
|
|
19
|
+
*/
|
|
20
|
+
function isCloseTo(expected, absoluteTolerance = 1e-9) {
|
|
21
|
+
return new IsCloseTo(expected, absoluteTolerance);
|
|
22
|
+
}
|
|
23
|
+
exports.isCloseTo = isCloseTo;
|
|
24
|
+
/**
|
|
25
|
+
* @package
|
|
26
|
+
*/
|
|
27
|
+
class IsCloseTo extends core_1.Expectation {
|
|
28
|
+
constructor(expected, absoluteTolerance) {
|
|
29
|
+
super((0, core_1.d) `have value close to ${expected} ±${absoluteTolerance}`, async (actor, actual) => {
|
|
30
|
+
const actualValue = await actor.answer(actual);
|
|
31
|
+
const expectedValue = await actor.answer(this.expected);
|
|
32
|
+
const tolerance = await actor.answer(this.absoluteTolerance);
|
|
33
|
+
const description = `have value close to ${expectedValue} ±${tolerance}`;
|
|
34
|
+
// short-circuit exact equality
|
|
35
|
+
if (actualValue === expectedValue) {
|
|
36
|
+
return new core_1.ExpectationMet(description, expectedValue, actualValue);
|
|
37
|
+
}
|
|
38
|
+
if (!(Number.isFinite(actualValue) && Number.isFinite(expectedValue))) {
|
|
39
|
+
return new core_1.ExpectationNotMet(description, expectedValue, actualValue);
|
|
40
|
+
}
|
|
41
|
+
const difference = Math.abs(actualValue - expectedValue);
|
|
42
|
+
const isClose = difference <= tolerance;
|
|
43
|
+
return isClose
|
|
44
|
+
? new core_1.ExpectationMet(description, expectedValue, actualValue)
|
|
45
|
+
: new core_1.ExpectationNotMet(description, expectedValue, actualValue);
|
|
46
|
+
});
|
|
47
|
+
this.expected = expected;
|
|
48
|
+
this.absoluteTolerance = absoluteTolerance;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=isCloseTo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isCloseTo.js","sourceRoot":"","sources":["../../src/expectations/isCloseTo.ts"],"names":[],"mappings":";;;AAAA,4CAAoH;AAEpH;;;;;;;;;;;;;;GAcG;AACH,SAAgB,SAAS,CAAC,QAA4B,EAAE,oBAAwC,IAAI;IAChG,OAAO,IAAI,SAAS,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;AACtD,CAAC;AAFD,8BAEC;AAED;;GAEG;AACH,MAAM,SAAU,SAAQ,kBAAmB;IAEvC,YACqB,QAA4B,EAC5B,iBAAqC;QAEtD,KAAK,CACD,IAAA,QAAC,EAAA,uBAAwB,QAAS,KAAM,iBAAkB,EAAE,EAC5D,KAAK,EAAE,KAAuB,EAAE,MAA0B,EAAE,EAAE;YAE1D,MAAM,WAAW,GAAa,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACzD,MAAM,aAAa,GAAW,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAChE,MAAM,SAAS,GAAe,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAEzE,MAAM,WAAW,GAAG,uBAAwB,aAAc,KAAM,SAAU,EAAE,CAAA;YAE5E,+BAA+B;YAC/B,IAAI,WAAW,KAAK,aAAa,EAAE;gBAC/B,OAAO,IAAI,qBAAc,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;aACtE;YAED,IAAI,CAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,EAAE;gBACpE,OAAO,IAAI,wBAAiB,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;aACzE;YAED,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,aAAa,CAAC,CAAA;YAExD,MAAM,OAAO,GAAG,UAAU,IAAI,SAAS,CAAC;YAExC,OAAO,OAAO;gBACV,CAAC,CAAC,IAAI,qBAAc,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC;gBAC7D,CAAC,CAAC,IAAI,wBAAiB,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;QACzE,CAAC,CACJ,CAAC;QA9Be,aAAQ,GAAR,QAAQ,CAAoB;QAC5B,sBAAiB,GAAjB,iBAAiB,CAAoB;IA8B1D,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-js/assertions",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.24",
|
|
4
4
|
"description": "Screenplay-style assertion library",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jan Molak",
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"url": "https://github.com/serenity-js/serenity-js/issues"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
|
-
"node": "^14 || ^16",
|
|
45
|
+
"node": "^14 || ^16 || ^18",
|
|
46
46
|
"npm": "^6 || ^7 || ^8"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@serenity-js/core": "3.0.0-rc.
|
|
49
|
+
"@serenity-js/core": "3.0.0-rc.24",
|
|
50
50
|
"tiny-types": "^1.18.4"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"ts-node": "10.8.2",
|
|
59
59
|
"typescript": "^4.7.4"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "76443ef557e876727b7dae9ef66d4e6612a3034b"
|
|
62
62
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, d, Expectation, ExpectationMet, ExpectationNotMet } from '@serenity-js/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @desc
|
|
5
|
+
* Expectation that the actual value is within a given ± absolute tolerance range of the expected value.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
9
|
+
* import { Ensure, isCloseTo } from '@serenity-js/assertions'
|
|
10
|
+
*
|
|
11
|
+
* await actorCalled('Iris').attemptsTo(
|
|
12
|
+
* Ensure.that(10.123, isCloseTo(10, 0.2))
|
|
13
|
+
* )
|
|
14
|
+
*
|
|
15
|
+
* @param {Answerable<number>} expected
|
|
16
|
+
* @param {Answerable<number>} [absoluteTolerance=1e-9]
|
|
17
|
+
*/
|
|
18
|
+
export function isCloseTo(expected: Answerable<number>, absoluteTolerance: Answerable<number> = 1e-9): Expectation<number> {
|
|
19
|
+
return new IsCloseTo(expected, absoluteTolerance);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @package
|
|
24
|
+
*/
|
|
25
|
+
class IsCloseTo extends Expectation<number> {
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
private readonly expected: Answerable<number>,
|
|
29
|
+
private readonly absoluteTolerance: Answerable<number>,
|
|
30
|
+
) {
|
|
31
|
+
super(
|
|
32
|
+
d`have value close to ${ expected } ±${ absoluteTolerance }`,
|
|
33
|
+
async (actor: AnswersQuestions, actual: Answerable<number>) => {
|
|
34
|
+
|
|
35
|
+
const actualValue: number = await actor.answer(actual);
|
|
36
|
+
const expectedValue: number = await actor.answer(this.expected);
|
|
37
|
+
const tolerance: number = await actor.answer(this.absoluteTolerance);
|
|
38
|
+
|
|
39
|
+
const description = `have value close to ${ expectedValue } ±${ tolerance }`
|
|
40
|
+
|
|
41
|
+
// short-circuit exact equality
|
|
42
|
+
if (actualValue === expectedValue) {
|
|
43
|
+
return new ExpectationMet(description, expectedValue, actualValue);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (! (Number.isFinite(actualValue) && Number.isFinite(expectedValue))) {
|
|
47
|
+
return new ExpectationNotMet(description, expectedValue, actualValue);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const difference = Math.abs(actualValue - expectedValue)
|
|
51
|
+
|
|
52
|
+
const isClose = difference <= tolerance;
|
|
53
|
+
|
|
54
|
+
return isClose
|
|
55
|
+
? new ExpectationMet(description, expectedValue, actualValue)
|
|
56
|
+
: new ExpectationNotMet(description, expectedValue, actualValue);
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|