assertron 11.1.4 → 11.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 (155) hide show
  1. package/cjs/assert-order/AssertOrder.d.ts.map +1 -1
  2. package/cjs/assert-order/AssertOrder.js +3 -1
  3. package/cjs/assert-order/AssertOrder.js.map +1 -1
  4. package/cjs/assert-order/InvalidOrder.d.ts +1 -1
  5. package/cjs/assert-order/InvalidOrder.d.ts.map +1 -1
  6. package/cjs/assert-order/InvalidOrder.js +4 -2
  7. package/cjs/assert-order/InvalidOrder.js.map +1 -1
  8. package/cjs/assert-order/StateMachine.d.ts +1 -1
  9. package/cjs/assert-order/StateMachine.d.ts.map +1 -1
  10. package/cjs/assert-order/StateMachine.js +17 -8
  11. package/cjs/assert-order/StateMachine.js.map +1 -1
  12. package/cjs/assert-order/types.d.ts.map +1 -1
  13. package/cjs/assertron/assertron.d.ts +1 -1
  14. package/cjs/assertron/assertron.d.ts.map +1 -1
  15. package/cjs/assertron/assertron.js.map +1 -1
  16. package/cjs/assertron/falsy.d.ts.map +1 -1
  17. package/cjs/assertron/falsy.js.map +1 -1
  18. package/cjs/assertron/isInstanceof.d.ts.map +1 -1
  19. package/cjs/assertron/isInstanceof.js.map +1 -1
  20. package/cjs/assertron/pathEqual.js.map +1 -1
  21. package/cjs/assertron/rejects.d.ts.map +1 -1
  22. package/cjs/assertron/rejects.js +3 -1
  23. package/cjs/assertron/rejects.js.map +1 -1
  24. package/cjs/assertron/repeat.d.ts.map +1 -1
  25. package/cjs/assertron/repeat.js +3 -1
  26. package/cjs/assertron/repeat.js.map +1 -1
  27. package/cjs/assertron/resolves.d.ts.map +1 -1
  28. package/cjs/assertron/resolves.js +3 -1
  29. package/cjs/assertron/resolves.js.map +1 -1
  30. package/cjs/assertron/satisfies.d.ts +1 -1
  31. package/cjs/assertron/satisfies.d.ts.map +1 -1
  32. package/cjs/assertron/satisfies.js.map +1 -1
  33. package/cjs/assertron/throws.d.ts +1 -1
  34. package/cjs/assertron/throws.d.ts.map +1 -1
  35. package/cjs/assertron/throws.js +7 -3
  36. package/cjs/assertron/throws.js.map +1 -1
  37. package/cjs/assertron/truthy.d.ts.map +1 -1
  38. package/cjs/assertron/truthy.js.map +1 -1
  39. package/cjs/errors.d.ts +3 -3
  40. package/cjs/errors.d.ts.map +1 -1
  41. package/cjs/errors.js.map +1 -1
  42. package/cjs/index.d.ts +2 -1
  43. package/cjs/index.d.ts.map +1 -1
  44. package/cjs/index.js +15 -1
  45. package/cjs/index.js.map +1 -1
  46. package/cjs/package.json +1 -1
  47. package/cjs/types.d.ts.map +1 -1
  48. package/cjs/utils/index.js.map +1 -1
  49. package/cjs/utils/isErrorConstructor.d.ts +1 -1
  50. package/cjs/utils/isErrorConstructor.d.ts.map +1 -1
  51. package/cjs/utils/isErrorConstructor.js.map +1 -1
  52. package/cjs/utils/notEqualMessage.js.map +1 -1
  53. package/cjs/utils/notSatisfiedMessage.d.ts +1 -1
  54. package/cjs/utils/notSatisfiedMessage.d.ts.map +1 -1
  55. package/cjs/utils/notSatisfiedMessage.js +8 -3
  56. package/cjs/utils/notSatisfiedMessage.js.map +1 -1
  57. package/cjs/utils/notThrownMessage.js.map +1 -1
  58. package/cjs/utils/promiseMessages.d.ts.map +1 -1
  59. package/cjs/utils/promiseMessages.js +8 -4
  60. package/cjs/utils/promiseMessages.js.map +1 -1
  61. package/cjs/utils/unexpectedErrorMessage.d.ts +1 -1
  62. package/cjs/utils/unexpectedErrorMessage.d.ts.map +1 -1
  63. package/cjs/utils/unexpectedErrorMessage.js +1 -2
  64. package/cjs/utils/unexpectedErrorMessage.js.map +1 -1
  65. package/esm/assert-order/AssertOrder.d.ts.map +1 -1
  66. package/esm/assert-order/AssertOrder.js +3 -1
  67. package/esm/assert-order/AssertOrder.js.map +1 -1
  68. package/esm/assert-order/InvalidOrder.d.ts +1 -1
  69. package/esm/assert-order/InvalidOrder.d.ts.map +1 -1
  70. package/esm/assert-order/InvalidOrder.js +4 -2
  71. package/esm/assert-order/InvalidOrder.js.map +1 -1
  72. package/esm/assert-order/StateMachine.d.ts +1 -1
  73. package/esm/assert-order/StateMachine.d.ts.map +1 -1
  74. package/esm/assert-order/StateMachine.js +17 -8
  75. package/esm/assert-order/StateMachine.js.map +1 -1
  76. package/esm/assert-order/types.d.ts.map +1 -1
  77. package/esm/assertron/assertron.d.ts +1 -1
  78. package/esm/assertron/assertron.d.ts.map +1 -1
  79. package/esm/assertron/assertron.js.map +1 -1
  80. package/esm/assertron/falsy.d.ts.map +1 -1
  81. package/esm/assertron/falsy.js.map +1 -1
  82. package/esm/assertron/isInstanceof.d.ts.map +1 -1
  83. package/esm/assertron/isInstanceof.js.map +1 -1
  84. package/esm/assertron/pathEqual.js.map +1 -1
  85. package/esm/assertron/rejects.d.ts.map +1 -1
  86. package/esm/assertron/rejects.js +3 -1
  87. package/esm/assertron/rejects.js.map +1 -1
  88. package/esm/assertron/repeat.d.ts.map +1 -1
  89. package/esm/assertron/repeat.js +3 -1
  90. package/esm/assertron/repeat.js.map +1 -1
  91. package/esm/assertron/resolves.d.ts.map +1 -1
  92. package/esm/assertron/resolves.js +3 -1
  93. package/esm/assertron/resolves.js.map +1 -1
  94. package/esm/assertron/satisfies.d.ts +1 -1
  95. package/esm/assertron/satisfies.d.ts.map +1 -1
  96. package/esm/assertron/satisfies.js.map +1 -1
  97. package/esm/assertron/throws.d.ts +1 -1
  98. package/esm/assertron/throws.d.ts.map +1 -1
  99. package/esm/assertron/throws.js +7 -3
  100. package/esm/assertron/throws.js.map +1 -1
  101. package/esm/assertron/truthy.d.ts.map +1 -1
  102. package/esm/assertron/truthy.js.map +1 -1
  103. package/esm/errors.d.ts +3 -3
  104. package/esm/errors.d.ts.map +1 -1
  105. package/esm/errors.js.map +1 -1
  106. package/esm/index.d.ts +2 -1
  107. package/esm/index.d.ts.map +1 -1
  108. package/esm/index.js +2 -1
  109. package/esm/index.js.map +1 -1
  110. package/esm/types.d.ts.map +1 -1
  111. package/esm/utils/index.js.map +1 -1
  112. package/esm/utils/isErrorConstructor.d.ts +1 -1
  113. package/esm/utils/isErrorConstructor.d.ts.map +1 -1
  114. package/esm/utils/isErrorConstructor.js.map +1 -1
  115. package/esm/utils/notEqualMessage.js.map +1 -1
  116. package/esm/utils/notSatisfiedMessage.d.ts +1 -1
  117. package/esm/utils/notSatisfiedMessage.d.ts.map +1 -1
  118. package/esm/utils/notSatisfiedMessage.js +8 -3
  119. package/esm/utils/notSatisfiedMessage.js.map +1 -1
  120. package/esm/utils/notThrownMessage.js.map +1 -1
  121. package/esm/utils/promiseMessages.d.ts.map +1 -1
  122. package/esm/utils/promiseMessages.js +8 -4
  123. package/esm/utils/promiseMessages.js.map +1 -1
  124. package/esm/utils/unexpectedErrorMessage.d.ts +1 -1
  125. package/esm/utils/unexpectedErrorMessage.d.ts.map +1 -1
  126. package/esm/utils/unexpectedErrorMessage.js +1 -2
  127. package/esm/utils/unexpectedErrorMessage.js.map +1 -1
  128. package/package.json +3 -3
  129. package/ts/assert-order/AssertOrder.ts +138 -143
  130. package/ts/assert-order/InvalidOrder.ts +23 -19
  131. package/ts/assert-order/StateMachine.ts +96 -89
  132. package/ts/assert-order/index.ts +0 -1
  133. package/ts/assert-order/internalInterfaces.ts +3 -3
  134. package/ts/assert-order/types.ts +5 -5
  135. package/ts/assertron/assertron.ts +39 -32
  136. package/ts/assertron/falsy.ts +1 -2
  137. package/ts/assertron/isInstanceof.ts +6 -3
  138. package/ts/assertron/pathEqual.ts +2 -2
  139. package/ts/assertron/rejects.ts +6 -4
  140. package/ts/assertron/repeat.ts +27 -21
  141. package/ts/assertron/resolves.ts +6 -4
  142. package/ts/assertron/satisfies.ts +28 -21
  143. package/ts/assertron/throws.ts +76 -55
  144. package/ts/assertron/truthy.ts +1 -4
  145. package/ts/errors.ts +9 -9
  146. package/ts/index.ts +17 -1
  147. package/ts/testUtils.ts +52 -55
  148. package/ts/types.ts +0 -1
  149. package/ts/utils/index.ts +1 -1
  150. package/ts/utils/isErrorConstructor.ts +2 -2
  151. package/ts/utils/notEqualMessage.ts +1 -1
  152. package/ts/utils/notSatisfiedMessage.ts +18 -14
  153. package/ts/utils/notThrownMessage.ts +1 -1
  154. package/ts/utils/promiseMessages.ts +12 -5
  155. package/ts/utils/unexpectedErrorMessage.ts +4 -3
@@ -1,9 +1,11 @@
1
1
  import { tersify } from 'tersify';
2
2
  export function notSatisfiedMessage(entries) {
3
- return entries.map(e => {
3
+ return entries
4
+ .map(e => {
4
5
  const path = formatPath(e.path);
5
6
  return `Expect ${path} to satisfy ${formatValue(e.expected)}, but received ${formatValue(e.actual)}`;
6
- }).join('\n');
7
+ })
8
+ .join('\n');
7
9
  }
8
10
  function formatPath(entries) {
9
11
  if (entries.length === 0)
@@ -12,7 +14,10 @@ function formatPath(entries) {
12
14
  if (isIndice(nodes[0])) {
13
15
  nodes.unshift('actual');
14
16
  }
15
- return nodes.map(n => isIndice(n) ? `[${n}]` : '.' + n).join('').slice(1);
17
+ return nodes
18
+ .map(n => (isIndice(n) ? `[${n}]` : '.' + n))
19
+ .join('')
20
+ .slice(1);
16
21
  }
17
22
  function isIndice(node) {
18
23
  return typeof node === 'number';
@@ -1 +1 @@
1
- {"version":3,"file":"notSatisfiedMessage.js","sourceRoot":"","sources":["../../ts/utils/notSatisfiedMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QACrB,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAC/B,OAAO,UAAU,IAAI,eAAe,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,kBAAkB,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAA;IACtG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC;AAED,SAAS,UAAU,CAAC,OAA4B;IAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QACtB,OAAO,QAAQ,CAAA;IACjB,MAAM,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,CAAA;IAC1B,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;QACtB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;KACxB;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC3E,CAAC;AAED,SAAS,QAAQ,CAAC,IAAqB;IACrC,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAA;AACjC,CAAC;AAED,SAAS,WAAW,CAAC,KAAU;IAC7B,OAAO,OAAO,CAAC,KAAK,CAAC,CAAA;AACvB,CAAC"}
1
+ {"version":3,"file":"notSatisfiedMessage.js","sourceRoot":"","sources":["../../ts/utils/notSatisfiedMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,mBAAmB,CAAC,OAAe;IAClD,OAAO,OAAO;SACZ,GAAG,CAAC,CAAC,CAAC,EAAE;QACR,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAC/B,OAAO,UAAU,IAAI,eAAe,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,kBAAkB,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAA;IACrG,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;AACb,CAAC;AAED,SAAS,UAAU,CAAC,OAA4B;IAC/C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAA;IACzC,MAAM,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,CAAA;IAC1B,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;QACvB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;KACvB;IACD,OAAO,KAAK;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;SAC5C,IAAI,CAAC,EAAE,CAAC;SACR,KAAK,CAAC,CAAC,CAAC,CAAA;AACX,CAAC;AAED,SAAS,QAAQ,CAAC,IAAqB;IACtC,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAA;AAChC,CAAC;AAED,SAAS,WAAW,CAAC,KAAU;IAC9B,OAAO,OAAO,CAAC,KAAK,CAAC,CAAA;AACtB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"notThrownMessage.js","sourceRoot":"","sources":["../../ts/utils/notThrownMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,gBAAgB,CAAC,KAAU;IACzC,OAAO,8CAA8C,OAAO,CAAC,KAAK,CAAC,YAAY,CAAA;AACjF,CAAC"}
1
+ {"version":3,"file":"notThrownMessage.js","sourceRoot":"","sources":["../../ts/utils/notThrownMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,gBAAgB,CAAC,KAAU;IAC1C,OAAO,8CAA8C,OAAO,CAAC,KAAK,CAAC,YAAY,CAAA;AAChF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"promiseMessages.d.ts","sourceRoot":"","sources":["../../ts/utils/promiseMessages.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,UAG5C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,UAG5C"}
1
+ {"version":3,"file":"promiseMessages.d.ts","sourceRoot":"","sources":["../../ts/utils/promiseMessages.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,UAK5C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,UAS5C"}
@@ -1,10 +1,14 @@
1
1
  import { tersify } from 'tersify';
2
2
  export function notRejectedMessage(value) {
3
- return `Expected promise to reject, but it resolves with ` + (typeof value === 'string'
4
- ? `'${value}'` : tersify(value, { maxLength: Infinity }));
3
+ return (`Expected promise to reject, but it resolves with ` +
4
+ (typeof value === 'string' ? `'${value}'` : tersify(value, { maxLength: Infinity })));
5
5
  }
6
6
  export function notResolvedMessage(error) {
7
- return `Expected promise to resolve, but it rejects with ` + (typeof error === 'string'
8
- ? `'${error}'` : error instanceof Error ? error : tersify(error, { maxLength: Infinity }));
7
+ return (`Expected promise to resolve, but it rejects with ` +
8
+ (typeof error === 'string'
9
+ ? `'${error}'`
10
+ : error instanceof Error
11
+ ? error
12
+ : tersify(error, { maxLength: Infinity })));
9
13
  }
10
14
  //# sourceMappingURL=promiseMessages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"promiseMessages.js","sourceRoot":"","sources":["../../ts/utils/promiseMessages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,kBAAkB,CAAC,KAAU;IAC3C,OAAO,mDAAmD,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ;QACrF,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAA;AAC7D,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAU;IAC3C,OAAO,mDAAmD,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ;QACrF,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAA;AAC9F,CAAC"}
1
+ {"version":3,"file":"promiseMessages.js","sourceRoot":"","sources":["../../ts/utils/promiseMessages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,kBAAkB,CAAC,KAAU;IAC5C,OAAO,CACN,mDAAmD;QACnD,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CACpF,CAAA;AACF,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAU;IAC5C,OAAO,CACN,mDAAmD;QACnD,CAAC,OAAO,KAAK,KAAK,QAAQ;YACzB,CAAC,CAAC,IAAI,KAAK,GAAG;YACd,CAAC,CAAC,KAAK,YAAY,KAAK;gBACxB,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CAC3C,CAAA;AACF,CAAC"}
@@ -1,3 +1,3 @@
1
- import { ErrorConstructor, ErrorValidator } from '../types.js';
1
+ import type { ErrorConstructor, ErrorValidator } from '../types.js';
2
2
  export declare function unexpectedErrorMessage(actual: any, expected: ErrorValidator | ErrorConstructor<any>): string;
3
3
  //# sourceMappingURL=unexpectedErrorMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unexpectedErrorMessage.d.ts","sourceRoot":"","sources":["../../ts/utils/unexpectedErrorMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAG9D,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,GAAG,gBAAgB,CAAC,GAAG,CAAC,UAGnG"}
1
+ {"version":3,"file":"unexpectedErrorMessage.d.ts","sourceRoot":"","sources":["../../ts/utils/unexpectedErrorMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGnE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,GAAG,gBAAgB,CAAC,GAAG,CAAC,UAInG"}
@@ -1,7 +1,6 @@
1
1
  import { tersify } from 'tersify';
2
2
  import { isErrorConstructor } from './isErrorConstructor.js';
3
3
  export function unexpectedErrorMessage(actual, expected) {
4
- return `Unexpected error. Expecting '${isErrorConstructor(expected) ?
5
- expected.name : tersify(expected)}' but received ${tersify(actual)}`;
4
+ return `Unexpected error. Expecting '${isErrorConstructor(expected) ? expected.name : tersify(expected)}' but received ${tersify(actual)}`;
6
5
  }
7
6
  //# sourceMappingURL=unexpectedErrorMessage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"unexpectedErrorMessage.js","sourceRoot":"","sources":["../../ts/utils/unexpectedErrorMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,MAAM,UAAU,sBAAsB,CAAC,MAAW,EAAE,QAAgD;IAClG,OAAO,gCAAgC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;QACnE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAA;AACxE,CAAC"}
1
+ {"version":3,"file":"unexpectedErrorMessage.js","sourceRoot":"","sources":["../../ts/utils/unexpectedErrorMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,MAAM,UAAU,sBAAsB,CAAC,MAAW,EAAE,QAAgD;IACnG,OAAO,gCACN,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAChE,kBAAkB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAA;AACpC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assertron",
3
- "version": "11.1.4",
3
+ "version": "11.2.1",
4
4
  "description": "A supplementary assertion library",
5
5
  "homepage": "https://github.com/unional/assertron",
6
6
  "bugs": {
@@ -60,7 +60,7 @@
60
60
  "path-equal": "^1.2.5",
61
61
  "satisfier": "^5.4.2",
62
62
  "tersify": "^3.11.1",
63
- "type-plus": "^6.0.0"
63
+ "type-plus": "^6.5.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@commitlint/cli": "^17.0.2",
@@ -89,7 +89,7 @@
89
89
  "npm-run-all": "^4.1.5",
90
90
  "pinst": "^3.0.0",
91
91
  "rimraf": "^3.0.2",
92
- "semantic-release": "^20.1.1",
92
+ "semantic-release": "^21.0.1",
93
93
  "size-limit": "^8.0.0",
94
94
  "ts-jest": "^29.0.0",
95
95
  "tslib": "^2.4.0",
@@ -5,147 +5,142 @@ import { StateMachine } from './StateMachine.js'
5
5
  // order.atMost(step, count) // exected to be executed at most `count` times
6
6
 
7
7
  export class AssertOrder {
8
- /**
9
- * Gets the current expecting step.
10
- */
11
- get currentStep() {
12
- return this.state.step
13
- }
14
-
15
- private state: StateMachine
16
- constructor(plan?: number) {
17
- this.state = new StateMachine(plan)
18
- }
19
-
20
- /**
21
- * Asserts the current step is `step`.
22
- * @param step expected step.
23
- */
24
- is(step: number) {
25
- this.assert('is', step)
26
- }
27
-
28
- /**
29
- * Asserts the current step is not `step`.
30
- * @param step not expected step.
31
- */
32
- not(step: number) {
33
- if (this.state.isValid(step)) {
34
- throw new InvalidOrder(this.state.get(), 'not', [step], { ssf: this.not })
35
- }
36
- }
37
-
38
- /**
39
- * Reset to specified step.
40
- */
41
- jump(step: number) {
42
- this.state.jump(step)
43
- }
44
-
45
- /**
46
- * Move to next step.
47
- */
48
- move() {
49
- this.state.move()
50
- }
51
-
52
- /**
53
- * Asserts the specified step will run once.
54
- */
55
- once(step: number) {
56
- this.assert('once', step)
57
- this.state.move()
58
- }
59
-
60
- on(step: number, assert: (step: number) => void) {
61
- this.state.on(step, () => {
62
- assert(step)
63
- })
64
- }
65
-
66
- atLeastOnce(step: number) {
67
- const nextStep = step + 1
68
- if (this.state.step === step) {
69
- this.state.move()
70
- return this.state.moveSubStep()
71
- }
72
- else if (this.state.step === nextStep && this.state.subStep > 0) {
73
- return this.state.moveSubStep()
74
- }
75
- else
76
- throw new InvalidOrder(this.state.get(), 'atLeastOnce', [step], { ssf: this.atLeastOnce })
77
- }
78
-
79
- any(steps: number[]) {
80
- const index = steps.indexOf(this.state.step)
81
- if (index === -1)
82
- throw new InvalidOrder(this.state.get(), 'any', [steps], { ssf: this.any })
83
-
84
- this.state.move()
85
- return steps[index]
86
- }
87
- onAny(steps: number[], ...asserts: Array<(...args: any[]) => any>) {
88
- steps.forEach(step => {
89
- this.state.on(step, () => {
90
- let firstError: any
91
- let hasPass = false
92
- asserts.forEach(assert => {
93
- try {
94
- assert(step)
95
- hasPass = true
96
- }
97
- catch (err) {
98
- if (!firstError) firstError = err
99
- }
100
- })
101
- if (!hasPass)
102
- throw firstError
103
- })
104
- })
105
- return
106
- }
107
- end(timeout: number): Promise<number>
108
- end(): number
109
- end(timeout?: number) {
110
- if (timeout) {
111
- return new Promise(r => {
112
- setTimeout(r, timeout)
113
- }).then(() => {
114
- return this.end()
115
- })
116
- }
117
-
118
- if (!this.state.isMaxStepDefined()) {
119
- this.state.stopAccepting()
120
- return this.state.getTimeTaken()
121
- }
122
-
123
- if (this.state.isAccepting()) {
124
- throw new InvalidOrder(this.state.get(), 'end', [], { ssf: this.end })
125
- }
126
- }
127
- exactly(step: number, times: number) {
128
- if (this.state.isNotValid(step))
129
- throw new InvalidOrder(this.state.get(), 'exactly', [step, times], { ssf: this.exactly })
130
-
131
- if (this.state.maxSubStep === undefined) {
132
- this.state.maxSubStep = times
133
- this.state.minSubStep = times
134
- }
135
-
136
- return this.state.moveSubStep()
137
- }
138
- wait(step: number): Promise<void>
139
- wait(step: number, callback: () => void): void
140
- wait(step: number, callback?: () => void) {
141
- if (callback)
142
- this.on(step, callback)
143
- else
144
- return new Promise<any>(a => { this.on(step, a) })
145
- }
146
- private assert(method: string, step: number) {
147
- if (this.state.isNotValid(step)) {
148
- throw new InvalidOrder(this.state.get(), method, [step], { ssf: (this as any)[method] })
149
- }
150
- }
8
+ /**
9
+ * Gets the current expecting step.
10
+ */
11
+ get currentStep() {
12
+ return this.state.step
13
+ }
14
+
15
+ private state: StateMachine
16
+ constructor(plan?: number) {
17
+ this.state = new StateMachine(plan)
18
+ }
19
+
20
+ /**
21
+ * Asserts the current step is `step`.
22
+ * @param step expected step.
23
+ */
24
+ is(step: number) {
25
+ this.assert('is', step)
26
+ }
27
+
28
+ /**
29
+ * Asserts the current step is not `step`.
30
+ * @param step not expected step.
31
+ */
32
+ not(step: number) {
33
+ if (this.state.isValid(step)) {
34
+ throw new InvalidOrder(this.state.get(), 'not', [step], { ssf: this.not })
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Reset to specified step.
40
+ */
41
+ jump(step: number) {
42
+ this.state.jump(step)
43
+ }
44
+
45
+ /**
46
+ * Move to next step.
47
+ */
48
+ move() {
49
+ this.state.move()
50
+ }
51
+
52
+ /**
53
+ * Asserts the specified step will run once.
54
+ */
55
+ once(step: number) {
56
+ this.assert('once', step)
57
+ this.state.move()
58
+ }
59
+
60
+ on(step: number, assert: (step: number) => void) {
61
+ this.state.on(step, () => {
62
+ assert(step)
63
+ })
64
+ }
65
+
66
+ atLeastOnce(step: number) {
67
+ const nextStep = step + 1
68
+ if (this.state.step === step) {
69
+ this.state.move()
70
+ return this.state.moveSubStep()
71
+ } else if (this.state.step === nextStep && this.state.subStep > 0) {
72
+ return this.state.moveSubStep()
73
+ } else throw new InvalidOrder(this.state.get(), 'atLeastOnce', [step], { ssf: this.atLeastOnce })
74
+ }
75
+
76
+ any(steps: number[]) {
77
+ const index = steps.indexOf(this.state.step)
78
+ if (index === -1) throw new InvalidOrder(this.state.get(), 'any', [steps], { ssf: this.any })
79
+
80
+ this.state.move()
81
+ return steps[index]
82
+ }
83
+ onAny(steps: number[], ...asserts: Array<(...args: any[]) => any>) {
84
+ steps.forEach(step => {
85
+ this.state.on(step, () => {
86
+ let firstError: any
87
+ let hasPass = false
88
+ asserts.forEach(assert => {
89
+ try {
90
+ assert(step)
91
+ hasPass = true
92
+ } catch (err) {
93
+ if (!firstError) firstError = err
94
+ }
95
+ })
96
+ if (!hasPass) throw firstError
97
+ })
98
+ })
99
+ return
100
+ }
101
+ end(timeout: number): Promise<number>
102
+ end(): number
103
+ end(timeout?: number) {
104
+ if (timeout) {
105
+ return new Promise(r => {
106
+ setTimeout(r, timeout)
107
+ }).then(() => {
108
+ return this.end()
109
+ })
110
+ }
111
+
112
+ if (!this.state.isMaxStepDefined()) {
113
+ this.state.stopAccepting()
114
+ return this.state.getTimeTaken()
115
+ }
116
+
117
+ if (this.state.isAccepting()) {
118
+ throw new InvalidOrder(this.state.get(), 'end', [], { ssf: this.end })
119
+ }
120
+ }
121
+ exactly(step: number, times: number) {
122
+ if (this.state.isNotValid(step))
123
+ throw new InvalidOrder(this.state.get(), 'exactly', [step, times], { ssf: this.exactly })
124
+
125
+ if (this.state.maxSubStep === undefined) {
126
+ this.state.maxSubStep = times
127
+ this.state.minSubStep = times
128
+ }
129
+
130
+ return this.state.moveSubStep()
131
+ }
132
+ wait(step: number): Promise<void>
133
+ wait(step: number, callback: () => void): void
134
+ wait(step: number, callback?: () => void) {
135
+ if (callback) this.on(step, callback)
136
+ else
137
+ return new Promise<any>(a => {
138
+ this.on(step, a)
139
+ })
140
+ }
141
+ private assert(method: string, step: number) {
142
+ if (this.state.isNotValid(step)) {
143
+ throw new InvalidOrder(this.state.get(), method, [step], { ssf: (this as any)[method] })
144
+ }
145
+ }
151
146
  }
@@ -1,35 +1,39 @@
1
1
  import { AssertionError } from '../errors.js'
2
- import { State } from './types.js'
2
+ import type { State } from './types.js'
3
3
 
4
4
  export class InvalidOrder extends AssertionError {
5
- constructor(public state: State, public method: string, public args: any[], options: AssertionError.Options) {
6
- super(method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args), options)
7
- }
5
+ constructor(
6
+ public state: State,
7
+ public method: string,
8
+ public args: any[],
9
+ options: AssertionError.Options
10
+ ) {
11
+ super(method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args), options)
12
+ }
8
13
  }
9
14
 
10
15
  function getEndMessage(state: State) {
11
- return `Planned for ${state.maxStep} step but expecting step ${state.step} when 'end()' is called`
16
+ return `Planned for ${state.maxStep} step but expecting step ${state.step} when 'end()' is called`
12
17
  }
13
18
 
14
19
  function getExpectingMessage(state: State, method: string, args: any[]) {
15
- return `Expecting ${getExpectingCalls(state)}, but received '${method}(${getMethodArgs(args)})'`
20
+ return `Expecting ${getExpectingCalls(state)}, but received '${method}(${getMethodArgs(args)})'`
16
21
  }
17
22
 
18
23
  function getExpectingCalls(state: State) {
19
- let message: string
20
- if (state.subStep === 0) {
21
- const methods = ['is', 'once', 'any']
22
- message = methods.map(
23
- m => `'${m}(${['any'].indexOf(m) === -1 ? state.step : `[${state.step}]`})'`
24
- ).join(', ')
25
- }
26
- else {
27
- const methods = ['exactly']
28
- message = methods.map(m => `'${m}(${state.step}, ${state.maxSubStep})'`).join(', ')
29
- }
30
- return message
24
+ let message: string
25
+ if (state.subStep === 0) {
26
+ const methods = ['is', 'once', 'any']
27
+ message = methods
28
+ .map(m => `'${m}(${['any'].indexOf(m) === -1 ? state.step : `[${state.step}]`})'`)
29
+ .join(', ')
30
+ } else {
31
+ const methods = ['exactly']
32
+ message = methods.map(m => `'${m}(${state.step}, ${state.maxSubStep})'`).join(', ')
33
+ }
34
+ return message
31
35
  }
32
36
 
33
37
  function getMethodArgs(args: any[]) {
34
- return args.map(a => Array.isArray(a) ? `[${a.join(', ')}]` : a).join(', ')
38
+ return args.map(a => (Array.isArray(a) ? `[${a.join(', ')}]` : a)).join(', ')
35
39
  }