assertron 9.0.9 → 9.2.1

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.
Files changed (234) hide show
  1. package/README.md +33 -57
  2. package/cjs/assert-order/AssertOrder.d.ts.map +1 -1
  3. package/cjs/assert-order/AssertOrder.js +169 -98
  4. package/cjs/assert-order/AssertOrder.js.map +1 -0
  5. package/cjs/assert-order/InvalidOrder.d.ts +2 -2
  6. package/cjs/assert-order/InvalidOrder.d.ts.map +1 -1
  7. package/cjs/assert-order/InvalidOrder.js +37 -8
  8. package/cjs/assert-order/InvalidOrder.js.map +1 -0
  9. package/cjs/assert-order/StateMachine.d.ts +1 -1
  10. package/cjs/assert-order/StateMachine.d.ts.map +1 -1
  11. package/cjs/assert-order/StateMachine.js +147 -57
  12. package/cjs/assert-order/StateMachine.js.map +1 -0
  13. package/cjs/assert-order/index.d.ts +3 -3
  14. package/cjs/assert-order/index.d.ts.map +1 -1
  15. package/cjs/assert-order/index.js +18 -5
  16. package/cjs/assert-order/index.js.map +1 -0
  17. package/cjs/assert-order/types.d.ts.map +1 -1
  18. package/cjs/assert-order/types.js +1 -1
  19. package/cjs/assert-order/types.js.map +1 -0
  20. package/cjs/assertron/assertron.d.ts +8 -8
  21. package/cjs/assertron/assertron.d.ts.map +1 -1
  22. package/cjs/assertron/assertron.js +21 -21
  23. package/cjs/assertron/assertron.js.map +1 -0
  24. package/cjs/assertron/falsy.d.ts.map +1 -1
  25. package/cjs/assertron/falsy.js +3 -3
  26. package/cjs/assertron/falsy.js.map +1 -0
  27. package/cjs/assertron/index.d.ts +1 -1
  28. package/cjs/assertron/index.d.ts.map +1 -1
  29. package/cjs/assertron/index.js +16 -3
  30. package/cjs/assertron/index.js.map +1 -0
  31. package/cjs/assertron/pathEqual.d.ts.map +1 -1
  32. package/cjs/assertron/pathEqual.js +4 -4
  33. package/cjs/assertron/pathEqual.js.map +1 -0
  34. package/cjs/assertron/rejects.d.ts +1 -1
  35. package/cjs/assertron/rejects.d.ts.map +1 -1
  36. package/cjs/assertron/rejects.js +4 -4
  37. package/cjs/assertron/rejects.js.map +1 -0
  38. package/cjs/assertron/repeat.d.ts.map +1 -1
  39. package/cjs/assertron/repeat.js +9 -7
  40. package/cjs/assertron/repeat.js.map +1 -0
  41. package/cjs/assertron/resolves.d.ts.map +1 -1
  42. package/cjs/assertron/resolves.js +4 -4
  43. package/cjs/assertron/resolves.js.map +1 -0
  44. package/cjs/assertron/satisfies.d.ts.map +1 -1
  45. package/cjs/assertron/satisfies.js +4 -4
  46. package/cjs/assertron/satisfies.js.map +1 -0
  47. package/cjs/assertron/throws.d.ts +1 -1
  48. package/cjs/assertron/throws.d.ts.map +1 -1
  49. package/cjs/assertron/throws.js +13 -11
  50. package/cjs/assertron/throws.js.map +1 -0
  51. package/cjs/assertron/truthy.d.ts.map +1 -1
  52. package/cjs/assertron/truthy.js +3 -3
  53. package/cjs/assertron/truthy.js.map +1 -0
  54. package/cjs/errors.d.ts.map +1 -1
  55. package/cjs/errors.js +32 -8
  56. package/cjs/errors.js.map +1 -0
  57. package/cjs/index.d.ts +5 -4
  58. package/cjs/index.d.ts.map +1 -1
  59. package/cjs/index.js +22 -7
  60. package/cjs/index.js.map +1 -0
  61. package/cjs/types.d.ts.map +1 -1
  62. package/cjs/types.js +1 -1
  63. package/cjs/types.js.map +1 -0
  64. package/cjs/utils/index.d.ts +6 -6
  65. package/cjs/utils/index.d.ts.map +1 -1
  66. package/cjs/utils/index.js +21 -8
  67. package/cjs/utils/index.js.map +1 -0
  68. package/cjs/utils/isErrorConstructor.d.ts +1 -1
  69. package/cjs/utils/isErrorConstructor.d.ts.map +1 -1
  70. package/cjs/utils/isErrorConstructor.js +1 -1
  71. package/cjs/utils/isErrorConstructor.js.map +1 -0
  72. package/cjs/utils/notEqualMessage.d.ts.map +1 -1
  73. package/cjs/utils/notEqualMessage.js +1 -1
  74. package/cjs/utils/notEqualMessage.js.map +1 -0
  75. package/cjs/utils/notSatisfiedMessage.d.ts.map +1 -1
  76. package/cjs/utils/notSatisfiedMessage.js +11 -3
  77. package/cjs/utils/notSatisfiedMessage.js.map +1 -0
  78. package/cjs/utils/notThrownMessage.d.ts.map +1 -1
  79. package/cjs/utils/notThrownMessage.js +1 -1
  80. package/cjs/utils/notThrownMessage.js.map +1 -0
  81. package/cjs/utils/promiseMessages.d.ts.map +1 -1
  82. package/cjs/utils/promiseMessages.js +1 -1
  83. package/cjs/utils/promiseMessages.js.map +1 -0
  84. package/cjs/utils/unexpectedErrorMessage.d.ts +1 -1
  85. package/cjs/utils/unexpectedErrorMessage.d.ts.map +1 -1
  86. package/cjs/utils/unexpectedErrorMessage.js +3 -3
  87. package/cjs/utils/unexpectedErrorMessage.js.map +1 -0
  88. package/esm/assert-order/AssertOrder.d.ts +41 -0
  89. package/esm/assert-order/AssertOrder.d.ts.map +1 -0
  90. package/esm/assert-order/AssertOrder.js +9 -3
  91. package/esm/assert-order/AssertOrder.js.map +1 -0
  92. package/esm/assert-order/InvalidOrder.d.ts +9 -0
  93. package/esm/assert-order/InvalidOrder.d.ts.map +1 -0
  94. package/esm/assert-order/InvalidOrder.js +20 -5
  95. package/esm/assert-order/InvalidOrder.js.map +1 -0
  96. package/esm/assert-order/StateMachine.d.ts +22 -0
  97. package/esm/assert-order/StateMachine.d.ts.map +1 -0
  98. package/esm/assert-order/StateMachine.js +37 -4
  99. package/esm/assert-order/StateMachine.js.map +1 -0
  100. package/esm/assert-order/index.d.ts +4 -0
  101. package/esm/assert-order/index.d.ts.map +1 -0
  102. package/esm/assert-order/index.js +4 -4
  103. package/esm/assert-order/index.js.map +1 -0
  104. package/esm/assert-order/types.d.ts +8 -0
  105. package/esm/assert-order/types.d.ts.map +1 -0
  106. package/esm/assert-order/types.js +1 -1
  107. package/esm/assert-order/types.js.map +1 -0
  108. package/esm/assertron/assertron.d.ts +21 -0
  109. package/esm/assertron/assertron.d.ts.map +1 -0
  110. package/esm/assertron/assertron.js +11 -11
  111. package/esm/assertron/assertron.js.map +1 -0
  112. package/esm/assertron/falsy.d.ts +2 -0
  113. package/esm/assertron/falsy.d.ts.map +1 -0
  114. package/esm/assertron/falsy.js +2 -2
  115. package/esm/assertron/falsy.js.map +1 -0
  116. package/esm/assertron/index.d.ts +2 -0
  117. package/esm/assertron/index.d.ts.map +1 -0
  118. package/esm/assertron/index.js +2 -2
  119. package/esm/assertron/index.js.map +1 -0
  120. package/esm/assertron/pathEqual.d.ts +2 -0
  121. package/esm/assertron/pathEqual.d.ts.map +1 -0
  122. package/esm/assertron/pathEqual.js +3 -3
  123. package/esm/assertron/pathEqual.js.map +1 -0
  124. package/esm/assertron/rejects.d.ts +2 -0
  125. package/esm/assertron/rejects.d.ts.map +1 -0
  126. package/esm/assertron/rejects.js +4 -4
  127. package/esm/assertron/rejects.js.map +1 -0
  128. package/esm/assertron/repeat.d.ts +6 -0
  129. package/esm/assertron/repeat.d.ts.map +1 -0
  130. package/esm/assertron/repeat.js +2 -2
  131. package/esm/assertron/repeat.js.map +1 -0
  132. package/esm/assertron/resolves.d.ts +2 -0
  133. package/esm/assertron/resolves.d.ts.map +1 -0
  134. package/esm/assertron/resolves.js +3 -3
  135. package/esm/assertron/resolves.js.map +1 -0
  136. package/esm/assertron/satisfies.d.ts +10 -0
  137. package/esm/assertron/satisfies.d.ts.map +1 -0
  138. package/esm/assertron/satisfies.js +3 -3
  139. package/esm/assertron/satisfies.js.map +1 -0
  140. package/esm/assertron/throws.d.ts +6 -0
  141. package/esm/assertron/throws.d.ts.map +1 -0
  142. package/esm/assertron/throws.js +3 -3
  143. package/esm/assertron/throws.js.map +1 -0
  144. package/esm/assertron/truthy.d.ts +2 -0
  145. package/esm/assertron/truthy.d.ts.map +1 -0
  146. package/esm/assertron/truthy.js +2 -2
  147. package/esm/assertron/truthy.js.map +1 -0
  148. package/esm/errors.d.ts +17 -0
  149. package/esm/errors.d.ts.map +1 -0
  150. package/esm/errors.js +14 -4
  151. package/esm/errors.js.map +1 -0
  152. package/esm/index.d.ts +7 -0
  153. package/esm/index.d.ts.map +1 -0
  154. package/esm/index.js +6 -5
  155. package/esm/index.js.map +1 -0
  156. package/esm/types.d.ts +3 -0
  157. package/esm/types.d.ts.map +1 -0
  158. package/esm/types.js +1 -1
  159. package/esm/types.js.map +1 -0
  160. package/esm/utils/index.d.ts +8 -0
  161. package/esm/utils/index.d.ts.map +1 -0
  162. package/esm/utils/index.js +7 -7
  163. package/esm/utils/index.js.map +1 -0
  164. package/esm/utils/isErrorConstructor.d.ts +3 -0
  165. package/esm/utils/isErrorConstructor.d.ts.map +1 -0
  166. package/esm/utils/isErrorConstructor.js +1 -1
  167. package/esm/utils/isErrorConstructor.js.map +1 -0
  168. package/esm/utils/notEqualMessage.d.ts +2 -0
  169. package/esm/utils/notEqualMessage.d.ts.map +1 -0
  170. package/esm/utils/notEqualMessage.js +1 -1
  171. package/esm/utils/notEqualMessage.js.map +1 -0
  172. package/esm/utils/notSatisfiedMessage.d.ts +3 -0
  173. package/esm/utils/notSatisfiedMessage.d.ts.map +1 -0
  174. package/esm/utils/notSatisfiedMessage.js +1 -1
  175. package/esm/utils/notSatisfiedMessage.js.map +1 -0
  176. package/esm/utils/notThrownMessage.d.ts +2 -0
  177. package/esm/utils/notThrownMessage.d.ts.map +1 -0
  178. package/esm/utils/notThrownMessage.js +1 -1
  179. package/esm/utils/notThrownMessage.js.map +1 -0
  180. package/esm/utils/promiseMessages.d.ts +3 -0
  181. package/esm/utils/promiseMessages.d.ts.map +1 -0
  182. package/esm/utils/promiseMessages.js +1 -1
  183. package/esm/utils/promiseMessages.js.map +1 -0
  184. package/esm/utils/unexpectedErrorMessage.d.ts +3 -0
  185. package/esm/utils/unexpectedErrorMessage.d.ts.map +1 -0
  186. package/esm/utils/unexpectedErrorMessage.js +2 -2
  187. package/esm/utils/unexpectedErrorMessage.js.map +1 -0
  188. package/package.json +48 -46
  189. package/{src → ts}/assert-order/AssertOrder.ts +2 -2
  190. package/{src → ts}/assert-order/InvalidOrder.ts +2 -2
  191. package/{src → ts}/assert-order/StateMachine.ts +1 -1
  192. package/ts/assert-order/index.ts +4 -0
  193. package/{src → ts}/assert-order/internalInterfaces.ts +0 -0
  194. package/{src → ts}/assert-order/types.ts +0 -0
  195. package/ts/assertron/assertron.ts +29 -0
  196. package/{src → ts}/assertron/falsy.ts +1 -1
  197. package/ts/assertron/index.ts +1 -0
  198. package/{src → ts}/assertron/pathEqual.ts +2 -2
  199. package/{src → ts}/assertron/rejects.ts +3 -3
  200. package/{src → ts}/assertron/repeat.ts +2 -2
  201. package/{src → ts}/assertron/resolves.ts +2 -2
  202. package/{src → ts}/assertron/satisfies.ts +2 -2
  203. package/{src → ts}/assertron/throws.ts +5 -5
  204. package/{src → ts}/assertron/truthy.ts +1 -1
  205. package/{src → ts}/errors.ts +1 -1
  206. package/ts/index.ts +7 -0
  207. package/{src → ts}/testUtils.ts +3 -3
  208. package/{src → ts}/types.ts +0 -0
  209. package/ts/utils/index.ts +12 -0
  210. package/{src → ts}/utils/isErrorConstructor.ts +1 -1
  211. package/{src → ts}/utils/notEqualMessage.ts +0 -1
  212. package/{src → ts}/utils/notSatisfiedMessage.ts +2 -2
  213. package/{src → ts}/utils/notThrownMessage.ts +0 -0
  214. package/{src → ts}/utils/promiseMessages.ts +0 -0
  215. package/{src → ts}/utils/unexpectedErrorMessage.ts +3 -3
  216. package/cjs/tsconfig.cjs.tsbuildinfo +0 -1
  217. package/esm/tsconfig.esm.tsbuildinfo +0 -1
  218. package/src/assert-order/AssertOrder.spec.ts +0 -446
  219. package/src/assert-order/InvalidOrder.spec.ts +0 -60
  220. package/src/assert-order/index.ts +0 -4
  221. package/src/assertron/assertron.spec.ts +0 -40
  222. package/src/assertron/assertron.ts +0 -29
  223. package/src/assertron/falsy.spec.ts +0 -20
  224. package/src/assertron/index.ts +0 -1
  225. package/src/assertron/pathEqual.spec.ts +0 -28
  226. package/src/assertron/rejects.spec.ts +0 -32
  227. package/src/assertron/repeat.spec.ts +0 -47
  228. package/src/assertron/resolves.spec.ts +0 -29
  229. package/src/assertron/satisfies.spec.ts +0 -159
  230. package/src/assertron/throws.spec.ts +0 -184
  231. package/src/assertron/truthy.spec.ts +0 -23
  232. package/src/index.ts +0 -6
  233. package/src/utils/index.ts +0 -12
  234. package/src/utils/notSatisfiedMessage.spec.ts +0 -31
@@ -1,446 +0,0 @@
1
- import t from 'assert';
2
- import a, { AssertOrder, InvalidOrder, State } from '..';
3
-
4
- test('is() expecting 1', () => {
5
- const order = new AssertOrder()
6
- order.is(1)
7
- })
8
-
9
- test('is() does not move the order forward', () => {
10
- const order = new AssertOrder()
11
- order.is(1)
12
- order.is(1)
13
- })
14
-
15
- test('is() with wrong step should throw', async () => {
16
- const order = new AssertOrder()
17
- await assertOrderThrows(() => order.is(0), { step: 1 }, 'is', 0)
18
- })
19
-
20
- test(`not() with right step should throw`, async () => {
21
- const order = new AssertOrder()
22
-
23
- await assertOrderThrows(() => order.not(1), { step: 1 }, 'not', 1)
24
- })
25
-
26
- test('not() with wrong step should pass', () => {
27
- const order = new AssertOrder()
28
- order.not(0)
29
- order.not(2)
30
- })
31
-
32
- test('move() to move to next step', () => {
33
- const order = new AssertOrder()
34
- order.move()
35
- order.is(2)
36
- })
37
-
38
- test('move(n) moves to step n', () => {
39
- const order = new AssertOrder()
40
- order.jump(3)
41
- order.is(3)
42
- })
43
-
44
- test('move(0) or negative also works', () => {
45
- const order = new AssertOrder()
46
- order.jump(0)
47
- order.is(0)
48
-
49
- order.jump(-2)
50
- order.is(-2)
51
-
52
- order.move()
53
- order.is(-1)
54
- })
55
-
56
- test('once() move to next step', () => {
57
- const order = new AssertOrder()
58
- order.once(1)
59
- order.is(2)
60
- })
61
-
62
- test('once() assert for current step', async () => {
63
- const order = new AssertOrder()
64
-
65
- await assertOrderThrows(() => order.once(0), { step: 1 }, 'once', 0)
66
- })
67
-
68
- test('on(1) will invoke at initial move', () => {
69
- const order = new AssertOrder()
70
- let called = false
71
- order.on(1, () => called = true)
72
-
73
- order.move()
74
-
75
- t.strictEqual(called, true)
76
- })
77
-
78
- test('jump(n) will not invoke on(y)', () => {
79
- const order = new AssertOrder()
80
- let called = false
81
- order.on(1, () => called = true)
82
-
83
- order.jump(1)
84
- t(!called)
85
- })
86
-
87
- test('on(0) will be invoked on jump(0) + move()', () => {
88
- const order = new AssertOrder()
89
- let called = false
90
- order.on(0, () => called = true)
91
-
92
- order.jump(0)
93
- order.move()
94
- t(called)
95
- })
96
-
97
- test('on(1) will be invoked on move()', () => {
98
- const order = new AssertOrder()
99
- let called = false
100
- order.on(1, () => called = true)
101
-
102
- order.move()
103
- t(called)
104
- })
105
-
106
- test('on(1) will be invoke on once(1)', () => {
107
- const order = new AssertOrder()
108
- let called = false
109
- order.on(1, () => called = true)
110
-
111
- order.once(1)
112
- t(called)
113
- })
114
-
115
- test('atLeastOnce(1) would move step forward', () => {
116
- const order = new AssertOrder()
117
- order.atLeastOnce(1)
118
- order.once(2)
119
- })
120
-
121
- test('atLeastOnce(1) can called multiple times', () => {
122
- const order = new AssertOrder()
123
- order.once(1)
124
- order.atLeastOnce(2)
125
- order.atLeastOnce(2)
126
- order.once(3)
127
- t.strictEqual(order.currentStep, 4)
128
- })
129
-
130
- test('atLeastOnce(1) should throws after once(1)', async () => {
131
- const order = new AssertOrder()
132
- order.once(1)
133
- await assertOrderThrows(() => order.atLeastOnce(1), { step: 2 }, 'atLeastOnce', 1)
134
- })
135
-
136
- test('atLeastOnce() returns sub step', () => {
137
- const order = new AssertOrder()
138
- t.strictEqual(order.atLeastOnce(1), 1)
139
- t.strictEqual(order.atLeastOnce(1), 2)
140
- t.strictEqual(order.atLeastOnce(2), 1)
141
- t.strictEqual(order.atLeastOnce(2), 2)
142
- t.strictEqual(order.atLeastOnce(3), 1)
143
- t.strictEqual(order.atLeastOnce(3), 2)
144
- })
145
-
146
- test.skip(`atLeast(n, m) where m <= 0 doesn't make sense`, () => { })
147
- test.skip(`atLeast(n, 2) pass`, () => { })
148
- test.skip(`atLeast(n, 2) fail`, () => { })
149
-
150
- test('any(2) should throws', async () => {
151
- const order = new AssertOrder()
152
-
153
- await assertOrderThrows(() => order.any([2]), { step: 1 }, 'any', [2])
154
- })
155
-
156
- test('any(2, 3) should throws', async () => {
157
- const order = new AssertOrder()
158
-
159
- await assertOrderThrows(() => order.any([2, 3]), { step: 1 }, 'any', [2, 3])
160
- })
161
-
162
- test('any(1) should move to next step', () => {
163
- const order = new AssertOrder()
164
-
165
- order.any([1])
166
-
167
- order.once(2)
168
- })
169
-
170
- test('any(1, 2) should pass with once(1) and move to step 3', () => {
171
- const order = new AssertOrder()
172
- order.once(1)
173
-
174
- order.any([1, 2])
175
-
176
- order.once(3)
177
- })
178
-
179
- test(`any() should returns the step it encountered`, () => {
180
- const order = new AssertOrder()
181
-
182
- t.strictEqual(order.any([1, 2, 3]), 1)
183
- t.strictEqual(order.any([1, 2, 3]), 2)
184
- t.strictEqual(order.any([1, 2, 3]), 3)
185
- })
186
-
187
- test(`onAny(1, fn) will not be invoked immediately`, () => {
188
- const order = new AssertOrder()
189
-
190
- order.onAny([1], () => t.fail('should be be invoked'))
191
- })
192
-
193
- test(`onAny(2, fn) invokes after move()`, () => {
194
- const order = new AssertOrder()
195
-
196
- order.onAny([2], step => t.strictEqual(step, 2))
197
- order.move()
198
- })
199
-
200
- test(`onAny() should not move step`, () => {
201
- const order = new AssertOrder()
202
- const o = new AssertOrder()
203
-
204
- order.onAny([1], step => {
205
- t.strictEqual(step, 1)
206
- o.once(2)
207
- })
208
- o.once(1)
209
- order.move()
210
-
211
- order.is(2)
212
- o.once(3)
213
- })
214
-
215
- test(`onAny([2,3], fn) invoke with the specific step`, () => {
216
- const order = new AssertOrder()
217
-
218
- const steps: number[] = []
219
- order.onAny([1, 2], step => steps.push(step))
220
-
221
- order.move()
222
- order.move()
223
- t.deepStrictEqual(steps, [1, 2])
224
- })
225
-
226
- test('onAny() passes if one of the assert functions passes ', () => {
227
- const a = new AssertOrder(2)
228
- let steps = ''
229
- a.onAny([1, 2], step => {
230
- steps += step
231
- t([1, 2].indexOf(step) >= 0)
232
- throw new Error('some error')
233
- }, step => {
234
- steps += step
235
- t([1, 2].indexOf(step) >= 0)
236
- })
237
- a.move()
238
- a.move()
239
-
240
- t.strictEqual(steps, '1122')
241
- })
242
-
243
- test(`onAny() throws if all assert functions throws`, () => {
244
- const o = new AssertOrder(2)
245
- o.onAny([1], () => {
246
- throw new Error('first error')
247
- }, () => {
248
- throw new Error('second error')
249
- })
250
- const err = a.throws(() => o.move())
251
- t.strictEqual(err.message, 'first error')
252
- })
253
-
254
- test('AssertOrder(0) accepts no step >= 1', () => {
255
- const order = new AssertOrder(0)
256
-
257
- const err = a.throws(() => order.once(1), InvalidOrder)
258
-
259
- t.strictEqual(err.state.maxStep, 0)
260
- })
261
-
262
- test('AssertOrder(1) accepts step 1 but not 2', () => {
263
- const order = new AssertOrder(1)
264
-
265
- order.once(1)
266
-
267
- const err = a.throws(() => order.once(2), InvalidOrder)
268
-
269
- t.strictEqual(err.state.maxStep, 1)
270
- })
271
-
272
- test('AssertOrder(0) can use jump(...)', () => {
273
- const order = new AssertOrder(0)
274
-
275
- order.jump(0)
276
- order.once(0)
277
- })
278
-
279
- test('end() should not throw if plan is not defined', () => {
280
- const order = new AssertOrder()
281
- order.end()
282
- })
283
-
284
- test('end() would mark to not accepting more steps if plan is not defined', () => {
285
- let order = new AssertOrder()
286
- order.end()
287
-
288
- let err = a.throws(() => order.once(1), InvalidOrder)
289
-
290
- t.strictEqual(err.state.maxStep, 0)
291
-
292
- order = new AssertOrder()
293
- order.once(1)
294
- order.end()
295
-
296
- err = a.throws(() => order.once(2), InvalidOrder)
297
-
298
- t.strictEqual(err.state.maxStep, 1)
299
- })
300
-
301
- test('end() passes with meeting planned step', () => {
302
- const order = new AssertOrder(1)
303
- order.once(1)
304
-
305
- order.end()
306
- })
307
-
308
- test('end() throws if planned step not met', () => {
309
- const order = new AssertOrder(2)
310
- order.once(1)
311
-
312
- const err = a.throws(() => order.end(), InvalidOrder)
313
-
314
- t.strictEqual(err.state.maxStep, 2)
315
- })
316
-
317
- test('end(n) waits n milliseconds before checking', async () => {
318
- const order = new AssertOrder(1)
319
-
320
- setTimeout(() => {
321
- order.once(1)
322
- }, 1)
323
-
324
- await order.end(2)
325
- })
326
-
327
- test('end(n) waits n milliseconds and fail when step not met', async () => {
328
- const order = new AssertOrder(1)
329
-
330
- setTimeout(() => {
331
- order.once(1)
332
- }, 100)
333
- const err = await a.throws(order.end(1), InvalidOrder)
334
-
335
- t.strictEqual(err.state.maxStep, 1)
336
- })
337
-
338
- test.skip(`exactly(n, 0) doesn't make sense`, () => { })
339
-
340
- test(`exactly(n, 1) is the same as once(n)`, () => {
341
- const order = new AssertOrder()
342
- order.exactly(1, 1)
343
- order.once(2)
344
- })
345
-
346
- test(`exactly(n, 2) moves to next step at sub step 2`, () => {
347
- const order = new AssertOrder()
348
- order.exactly(1, 2)
349
- order.exactly(1, 2)
350
- order.once(2)
351
- })
352
-
353
- test(`exactly() returns the sub step`, () => {
354
- const order = new AssertOrder()
355
- t.strictEqual(order.exactly(1, 2), 1)
356
- t.strictEqual(order.exactly(1, 2), 2)
357
- })
358
-
359
- test('jump(0) restore 0 based step AssertOrder', () => {
360
- const order = new AssertOrder()
361
- order.jump(0)
362
- order.once(0)
363
- order.once(1)
364
- })
365
-
366
- test('end() returns time taken', () => {
367
- const order = new AssertOrder()
368
- let i = 10000
369
- while (i) i--
370
- t(order.end() > 0)
371
- })
372
-
373
- test('end(number) returns promise with time taken', async () => {
374
- const order = new AssertOrder()
375
- let i = 10000
376
- while (i) i--
377
- t(await order.end(1) > 0)
378
- })
379
-
380
- test('calling end() with planned step met will pass', () => {
381
- const order = new AssertOrder(1)
382
- order.once(1)
383
- order.end()
384
- })
385
-
386
- test('calling end() early will throw', () => {
387
- const order = new AssertOrder(2)
388
- order.once(1)
389
- a.throws(() => order.end())
390
- })
391
-
392
- test('calling end() without planned step will pass', () => {
393
- const order = new AssertOrder()
394
- order.end()
395
- })
396
-
397
- test('wait(step) will wait for specific step to happen', async () => {
398
- const order = new AssertOrder()
399
-
400
- setImmediate(() => {
401
- order.once(1)
402
- })
403
- await order.wait(1)
404
- t.strictEqual(order.currentStep, 2)
405
- })
406
-
407
- test('wait(step, callback) will execute the callback and return void', async () => {
408
- const order = new AssertOrder(2)
409
-
410
- order.wait(1, () => {
411
- order.once(2)
412
- })
413
- order.once(1)
414
-
415
- return order.end(100)
416
- })
417
-
418
- test('wait(step, callback) will execute the async callback but not wait for it and return void', async () => {
419
- const order = new AssertOrder(1)
420
- const o2 = new AssertOrder(1)
421
-
422
- order.wait(1, () => {
423
- return new Promise<void>(a => {
424
- setImmediate(() => {
425
- o2.once(1)
426
- a()
427
- })
428
- })
429
- })
430
- order.once(1)
431
-
432
- order.end()
433
- return o2.end(100)
434
- })
435
-
436
- async function assertOrderThrows(fn: () => any, state: Partial<State>, method: string, ...args: any[]) {
437
- const err = await a.throws(fn, InvalidOrder)
438
- t.strictEqual(err.method, method)
439
- t.deepStrictEqual(err.args, args)
440
- if (state.step) {
441
- t.strictEqual(err.state.step, state.step)
442
- }
443
- if (state.subStep) {
444
- t.strictEqual(err.state.subStep, state.subStep)
445
- }
446
- }
@@ -1,60 +0,0 @@
1
- import t from 'assert';
2
- import { AssertOrder } from '..';
3
- import { assertThrows } from '../testUtils';
4
-
5
- test('error message for once()', () => {
6
- const o = new AssertOrder()
7
- const err = assertThrows(() => o.once(2))
8
- t.strictEqual(err.message, `Expecting 'is(1)', 'once(1)', 'any([1])', but received 'once(2)'`)
9
- })
10
-
11
- test('error message for multi-step methods', () => {
12
- const o = new AssertOrder()
13
- o.exactly(1, 2)
14
- const err = assertThrows(() => o.once(2))
15
- t.strictEqual(err.message, `Expecting 'exactly(1, 2)', but received 'once(2)'`)
16
- })
17
-
18
- test('error message for exactly() called too many times', () => {
19
- const o = new AssertOrder()
20
- o.exactly(1, 2)
21
- o.exactly(1, 2)
22
- const err = assertThrows(() => o.exactly(1, 2))
23
- t.strictEqual(err.message, `Expecting 'is(2)', 'once(2)', 'any([2])', but received 'exactly(1, 2)'`)
24
- })
25
-
26
- test('error message for is()', () => {
27
- const order = new AssertOrder()
28
- const err = assertThrows(() => order.is(0))
29
- t.strictEqual(err.message, `Expecting 'is(1)', 'once(1)', 'any([1])', but received 'is(0)'`)
30
- })
31
-
32
- test(`error message for not()`, () => {
33
- const order = new AssertOrder()
34
- const err = assertThrows(() => order.not(1))
35
- t.strictEqual(err.message, `Expecting 'is(1)', 'once(1)', 'any([1])', but received 'not(1)'`)
36
- })
37
-
38
- test('error message for atLeastOnce()', () => {
39
- const order = new AssertOrder()
40
- order.once(1)
41
- const err = assertThrows(() => order.atLeastOnce(1))
42
- t.strictEqual(err.message, `Expecting 'is(2)', 'once(2)', 'any([2])', but received 'atLeastOnce(1)'`)
43
- })
44
-
45
- test('error message for any()', () => {
46
- const order = new AssertOrder()
47
-
48
- let err = assertThrows(() => order.any([2]))
49
- t.strictEqual(err.message, `Expecting 'is(1)', 'once(1)', 'any([1])', but received 'any([2])'`)
50
-
51
- err = assertThrows(() => order.any([2, 3]))
52
- t.strictEqual(err.message, `Expecting 'is(1)', 'once(1)', 'any([1])', but received 'any([2, 3])'`)
53
- })
54
-
55
- test('error message for end()', () => {
56
- const order = new AssertOrder(1)
57
-
58
- const err = assertThrows(() => order.end())
59
- t.strictEqual(err.message, `Planned for 1 step but expecting step 1 when 'end()' is called`)
60
- })
@@ -1,4 +0,0 @@
1
- export * from './AssertOrder'
2
- export * from './InvalidOrder'
3
- export * from './types'
4
-
@@ -1,40 +0,0 @@
1
- import a, { AssertionError } from '..'
2
- import { assertThrows, noStackTraceFor } from '../testUtils'
3
-
4
- describe('false()', () => {
5
- test('non-false statement throws', () => {
6
- assertThrows(() => a.false(true), AssertionError)
7
- assertThrows(() => a.false(0), AssertionError)
8
- assertThrows(() => a.false(''), AssertionError)
9
- assertThrows(() => a.false({}), AssertionError)
10
- assertThrows(() => a.false(() => false), AssertionError)
11
- })
12
-
13
- test('false statement pass', () => {
14
- a.false(false)
15
- })
16
-
17
- test('does not contain internal stack trace', () => {
18
- const err = assertThrows(() => a.false(true), AssertionError)
19
- noStackTraceFor('assertron.ts', err)
20
- })
21
- })
22
-
23
- describe('true()', () => {
24
- test('non-true statement throws', () => {
25
- assertThrows(() => a.true(false), AssertionError)
26
- assertThrows(() => a.true(1), AssertionError)
27
- assertThrows(() => a.true('a'), AssertionError)
28
- assertThrows(() => a.true({}), AssertionError)
29
- assertThrows(() => a.true(() => true), AssertionError)
30
- })
31
-
32
- test('true statement pass', () => {
33
- a.true(true)
34
- })
35
-
36
- test('does not contain internal stack trace', () => {
37
- const err = assertThrows(() => a.true(false), AssertionError)
38
- noStackTraceFor('assertron.ts', err)
39
- })
40
- })
@@ -1,29 +0,0 @@
1
- import { AssertionError } from '../errors'
2
- import { notEqualMessage } from '../utils'
3
- import { falsy } from './falsy'
4
- import { pathEqual } from './pathEqual'
5
- import { rejects } from './rejects'
6
- import { repeat } from './repeat'
7
- import { resolves } from './resolves'
8
- import { satisfies } from './satisfies'
9
- import { throws } from './throws'
10
- import { truthy } from './truthy'
11
-
12
- export const assertron = {
13
- false(value: any) {
14
- if (value !== false)
15
- throw new AssertionError(notEqualMessage(value, false), { ssf: assertron.false })
16
- },
17
- falsy,
18
- pathEqual,
19
- rejects,
20
- repeat,
21
- resolves,
22
- satisfies,
23
- throws,
24
- true(value: any) {
25
- if (value !== true)
26
- throw new AssertionError(notEqualMessage(value, true), { ssf: assertron.true })
27
- },
28
- truthy
29
- }
@@ -1,20 +0,0 @@
1
- import a, { AssertionError } from '..'
2
- import { assertThrows, noStackTraceFor } from '../testUtils'
3
-
4
- test('non-false statement throws', () => {
5
- assertThrows(() => a.falsy(true), AssertionError)
6
- assertThrows(() => a.falsy(1 === 1), AssertionError)
7
- assertThrows(() => a.falsy(1), AssertionError)
8
- assertThrows(() => a.falsy({}), AssertionError)
9
- assertThrows(() => a.falsy(() => true), AssertionError)
10
- })
11
-
12
- test('does not contain internal stack trace', () => {
13
- const err = assertThrows(() => a.falsy(true), AssertionError)
14
- noStackTraceFor('falsy.ts', err)
15
- })
16
-
17
- test('false statement pass', () => {
18
- a.falsy(false)
19
- a.falsy(1 === 2 as any)
20
- })
@@ -1 +0,0 @@
1
- export * from './assertron'
@@ -1,28 +0,0 @@
1
- import assertron, { AssertionError } from '..'
2
- import { assertThrows, noStackTraceFor } from '../testUtils'
3
-
4
- test('path with same style passes', () => {
5
- assertron.pathEqual('a', 'a')
6
- assertron.pathEqual('a/b', 'a/b')
7
- assertron.pathEqual('a\\b', 'a\\b')
8
- })
9
-
10
- test('same style different value throws', () => {
11
- assertThrows(() => assertron.pathEqual('a', 'b'))
12
- })
13
-
14
- test('UNIX style matches Windows style', () => {
15
- assertron.pathEqual('a/b', 'a\\b')
16
- assertron.pathEqual('a/b/c', 'a\\b\\c')
17
- assertron.pathEqual('a\\b', 'a/b')
18
- assertron.pathEqual('a\\b\\c', 'a/b/c')
19
- })
20
-
21
- test(`/d/foo should match d:\\foo`, () => {
22
- assertron.pathEqual('/d/foo', 'd:\\foo')
23
- })
24
-
25
- test('does not contain internal stack trace', () => {
26
- const err = assertThrows(() => assertron.pathEqual('a', 'b'), AssertionError)
27
- noStackTraceFor('pathEqual.ts', err)
28
- })
@@ -1,32 +0,0 @@
1
- import t from 'assert'
2
- import a from '..'
3
- import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
4
-
5
- test('pass on rejected promise', async () => {
6
- await a.rejects(Promise.reject(1))
7
- })
8
-
9
- test('throws on resolved string promise', async () => {
10
- const err = await a.throws(a.rejects(Promise.resolve('abc')))
11
- t.strictEqual(err.message, `Expected promise to reject, but it resolves with 'abc'`)
12
- })
13
-
14
- test('throws on resolved boolean promise', async () => {
15
- const err = await a.throws(a.rejects(Promise.resolve(true)))
16
- t.strictEqual(err.message, `Expected promise to reject, but it resolves with true`)
17
- })
18
-
19
- test('throws on resolved object promise', async () => {
20
- const err = await a.throws(a.rejects(Promise.resolve(2)))
21
- t.strictEqual(err.message, `Expected promise to reject, but it resolves with 2`)
22
- })
23
-
24
- test('throws on resolved object promise', async () => {
25
- const err = await a.throws(a.rejects(Promise.resolve({ a: 1 })))
26
- t.strictEqual(err.message, `Expected promise to reject, but it resolves with { a: 1 }`)
27
- })
28
-
29
- test('does not contain internal stack trace', async () => {
30
- const err = await assertAsyncThrows(() => a.rejects(Promise.resolve({ a: 1 })))
31
- noStackTraceFor('rejects.ts', err)
32
- })