@serenity-js/assertions 3.0.0-rc.3 → 3.0.0-rc.30

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 (120) hide show
  1. package/CHANGELOG.md +51 -1913
  2. package/README.md +10 -8
  3. package/lib/Ensure.d.ts +56 -77
  4. package/lib/Ensure.d.ts.map +1 -0
  5. package/lib/Ensure.js +62 -90
  6. package/lib/Ensure.js.map +1 -1
  7. package/lib/expectations/and.d.ts +22 -1
  8. package/lib/expectations/and.d.ts.map +1 -0
  9. package/lib/expectations/and.js +26 -6
  10. package/lib/expectations/and.js.map +1 -1
  11. package/lib/expectations/contain.d.ts +26 -1
  12. package/lib/expectations/contain.d.ts.map +1 -0
  13. package/lib/expectations/contain.js +25 -1
  14. package/lib/expectations/contain.js.map +1 -1
  15. package/lib/expectations/containAtLeastOneItemThat.d.ts +23 -1
  16. package/lib/expectations/containAtLeastOneItemThat.d.ts.map +1 -0
  17. package/lib/expectations/containAtLeastOneItemThat.js +37 -9
  18. package/lib/expectations/containAtLeastOneItemThat.js.map +1 -1
  19. package/lib/expectations/containItemsWhereEachItem.d.ts +23 -1
  20. package/lib/expectations/containItemsWhereEachItem.d.ts.map +1 -0
  21. package/lib/expectations/containItemsWhereEachItem.js +37 -9
  22. package/lib/expectations/containItemsWhereEachItem.js.map +1 -1
  23. package/lib/expectations/endsWith.d.ts +20 -0
  24. package/lib/expectations/endsWith.d.ts.map +1 -0
  25. package/lib/expectations/endsWith.js +19 -0
  26. package/lib/expectations/endsWith.js.map +1 -1
  27. package/lib/expectations/equals.d.ts +26 -0
  28. package/lib/expectations/equals.d.ts.map +1 -0
  29. package/lib/expectations/equals.js +25 -0
  30. package/lib/expectations/equals.js.map +1 -1
  31. package/lib/expectations/includes.d.ts +20 -0
  32. package/lib/expectations/includes.d.ts.map +1 -0
  33. package/lib/expectations/includes.js +19 -0
  34. package/lib/expectations/includes.js.map +1 -1
  35. package/lib/expectations/index.d.ts +3 -0
  36. package/lib/expectations/index.d.ts.map +1 -0
  37. package/lib/expectations/index.js +7 -1
  38. package/lib/expectations/index.js.map +1 -1
  39. package/lib/expectations/isAfter.d.ts +40 -0
  40. package/lib/expectations/isAfter.d.ts.map +1 -0
  41. package/lib/expectations/isAfter.js +39 -0
  42. package/lib/expectations/isAfter.js.map +1 -1
  43. package/lib/expectations/isBefore.d.ts +40 -0
  44. package/lib/expectations/isBefore.d.ts.map +1 -0
  45. package/lib/expectations/isBefore.js +39 -0
  46. package/lib/expectations/isBefore.js.map +1 -1
  47. package/lib/expectations/isCloseTo.d.ts +24 -0
  48. package/lib/expectations/isCloseTo.d.ts.map +1 -0
  49. package/lib/expectations/isCloseTo.js +57 -0
  50. package/lib/expectations/isCloseTo.js.map +1 -0
  51. package/lib/expectations/isFalse.d.ts +19 -0
  52. package/lib/expectations/isFalse.d.ts.map +1 -0
  53. package/lib/expectations/isFalse.js +18 -0
  54. package/lib/expectations/isFalse.js.map +1 -1
  55. package/lib/expectations/isGreaterThan.d.ts +43 -0
  56. package/lib/expectations/isGreaterThan.d.ts.map +1 -0
  57. package/lib/expectations/isGreaterThan.js +42 -0
  58. package/lib/expectations/isGreaterThan.js.map +1 -1
  59. package/lib/expectations/isLessThan.d.ts +43 -0
  60. package/lib/expectations/isLessThan.d.ts.map +1 -0
  61. package/lib/expectations/isLessThan.js +42 -0
  62. package/lib/expectations/isLessThan.js.map +1 -1
  63. package/lib/expectations/isPresent.d.ts +64 -0
  64. package/lib/expectations/isPresent.d.ts.map +1 -0
  65. package/lib/expectations/isPresent.js +99 -0
  66. package/lib/expectations/isPresent.js.map +1 -0
  67. package/lib/expectations/isTrue.d.ts +19 -0
  68. package/lib/expectations/isTrue.d.ts.map +1 -0
  69. package/lib/expectations/isTrue.js +18 -0
  70. package/lib/expectations/isTrue.js.map +1 -1
  71. package/lib/expectations/matches.d.ts +21 -1
  72. package/lib/expectations/matches.d.ts.map +1 -0
  73. package/lib/expectations/matches.js +19 -0
  74. package/lib/expectations/matches.js.map +1 -1
  75. package/lib/expectations/not.d.ts +23 -1
  76. package/lib/expectations/not.d.ts.map +1 -0
  77. package/lib/expectations/not.js +30 -10
  78. package/lib/expectations/not.js.map +1 -1
  79. package/lib/expectations/or.d.ts +22 -1
  80. package/lib/expectations/or.d.ts.map +1 -0
  81. package/lib/expectations/or.js +39 -14
  82. package/lib/expectations/or.js.map +1 -1
  83. package/lib/expectations/property.d.ts +61 -1
  84. package/lib/expectations/property.d.ts.map +1 -0
  85. package/lib/expectations/property.js +66 -10
  86. package/lib/expectations/property.js.map +1 -1
  87. package/lib/expectations/startsWith.d.ts +20 -0
  88. package/lib/expectations/startsWith.d.ts.map +1 -0
  89. package/lib/expectations/startsWith.js +19 -0
  90. package/lib/expectations/startsWith.js.map +1 -1
  91. package/lib/index.d.ts +1 -1
  92. package/lib/index.d.ts.map +1 -0
  93. package/lib/index.js +5 -5
  94. package/lib/index.js.map +1 -1
  95. package/package.json +16 -40
  96. package/src/Ensure.ts +75 -101
  97. package/src/expectations/and.ts +39 -18
  98. package/src/expectations/contain.ts +26 -2
  99. package/src/expectations/containAtLeastOneItemThat.ts +59 -14
  100. package/src/expectations/containItemsWhereEachItem.ts +59 -14
  101. package/src/expectations/endsWith.ts +19 -0
  102. package/src/expectations/equals.ts +25 -0
  103. package/src/expectations/includes.ts +19 -0
  104. package/src/expectations/index.ts +2 -0
  105. package/src/expectations/isAfter.ts +39 -0
  106. package/src/expectations/isBefore.ts +39 -0
  107. package/src/expectations/isCloseTo.ts +66 -0
  108. package/src/expectations/isFalse.ts +19 -1
  109. package/src/expectations/isGreaterThan.ts +42 -0
  110. package/src/expectations/isLessThan.ts +42 -0
  111. package/src/expectations/isPresent.ts +107 -0
  112. package/src/expectations/isTrue.ts +19 -1
  113. package/src/expectations/matches.ts +20 -1
  114. package/src/expectations/not.ts +36 -15
  115. package/src/expectations/or.ts +49 -26
  116. package/src/expectations/property.ts +78 -21
  117. package/src/expectations/startsWith.ts +19 -0
  118. package/src/index.ts +0 -1
  119. package/tsconfig.build.json +10 -0
  120. package/tsconfig.eslint.json +0 -10
@@ -1,33 +1,90 @@
1
- import { AnswersQuestions, Expectation, ExpectationMet, ExpectationNotMet, ExpectationOutcome } from '@serenity-js/core';
2
- import { formatted } from '@serenity-js/core/lib/io';
1
+ import { Answerable, AnswersQuestions, Expectation, ExpectationMet, ExpectationNotMet } from '@serenity-js/core';
3
2
 
4
- export function property<Actual, Property extends keyof Actual>(
5
- propertyName: Property,
6
- expectation: Expectation<any, Actual[Property]>,
7
- ): Expectation<Actual[Property], Actual> {
3
+ /**
4
+ * Creates an {@apilink Expectation|expectation} that is met when the value of
5
+ * the `actual[propertyName]` meets the `expectation`.
6
+ *
7
+ * ## Ensuring that an array has an item
8
+ *
9
+ * ```ts
10
+ * import { actorCalled } from '@serenity-js/core'
11
+ * import { Ensure, property } from '@serenity-js/assertions'
12
+ *
13
+ * const list = [ 'hello', 'world' ]
14
+ *
15
+ * await actorCalled('Ester').attemptsTo(
16
+ * Ensure.that(list, property(0, isPresent())),
17
+ * )
18
+ * ```
19
+ *
20
+ * ## Ensuring that the property meets an expectation
21
+ *
22
+ * ```ts
23
+ * import { actorCalled } from '@serenity-js/core'
24
+ * import { Ensure, property, equals } from '@serenity-js/assertions'
25
+ *
26
+ * const list = [ 'hello', 'world' ]
27
+ *
28
+ * await actorCalled('Ester').attemptsTo(
29
+ * Ensure.that(list, property('length', equals(2))),
30
+ * )
31
+ * ```
32
+ *
33
+ * ## Asserting on a list of objects
34
+ *
35
+ * ```ts
36
+ * import { actorCalled } from '@serenity-js/core'
37
+ * import { Ensure, property, equals } from '@serenity-js/assertions'
38
+ *
39
+ * const developers = [{
40
+ * name: 'Jan',
41
+ * id: '@jan-molak',
42
+ * }, {
43
+ * name: 'John',
44
+ * id: '@wakaleo',
45
+ * }]
46
+ *
47
+ * await actorCalled('Ester').attemptsTo(
48
+ * Ensure.that(
49
+ * developers,
50
+ * containItemsWhereEachItem(
51
+ * property('id', startsWith('@'))
52
+ * ),
53
+ * ),
54
+ * )
55
+ * ```
56
+ *
57
+ * @param propertyName
58
+ * @param expectation
59
+ *
60
+ * @group Expectations
61
+ */
62
+ export function property<Actual extends object, PropertyName extends keyof Actual>(
63
+ propertyName: PropertyName,
64
+ expectation: Expectation<Actual[PropertyName]>
65
+ ): Expectation<Actual> {
8
66
  return new HasProperty(propertyName, expectation);
9
67
  }
10
68
 
11
69
  /**
12
70
  * @package
13
71
  */
14
- class HasProperty<Property extends keyof Actual, Actual> extends Expectation<Actual[Property], Actual> {
72
+ class HasProperty<Actual extends object, PropertyName extends keyof Actual> extends Expectation<Actual> {
15
73
  constructor(
16
- private readonly propertyName: Property,
17
- private readonly expectation: Expectation<any, Actual[Property]>,
74
+ private readonly propertyName: PropertyName,
75
+ expectation: Expectation<Actual[PropertyName]>,
18
76
  ) {
19
- super(formatted `have property ${ propertyName } that does ${ expectation }`);
20
- }
21
-
22
- answeredBy(actor: AnswersQuestions): (actual: Actual) => Promise<ExpectationOutcome<Actual[Property], any>> {
23
-
24
- return (actual: Actual) =>
25
- this.expectation.answeredBy(actor)(actual[this.propertyName])
26
- .then((outcome: ExpectationOutcome<any, Actual[Property]>) => {
77
+ const subject = `have property ${ String(propertyName) } that does ${ expectation }`;
78
+ super(
79
+ subject,
80
+ async (actor: AnswersQuestions, actual: Answerable<Actual>) => {
81
+ const actualValue = await actor.answer(actual);
82
+ const outcome = await actor.answer(expectation.isMetFor(actualValue[propertyName]));
27
83
 
28
- return outcome instanceof ExpectationMet
29
- ? new ExpectationMet(this.toString(), outcome.expected, actual[this.propertyName])
30
- : new ExpectationNotMet(this.toString(), outcome.expected, actual[this.propertyName]);
31
- });
84
+ return outcome instanceof ExpectationMet
85
+ ? new ExpectationMet<any, Actual>(subject, outcome.expected, actualValue)
86
+ : new ExpectationNotMet<any, Actual>(subject, outcome.expected, actualValue);
87
+ },
88
+ );
32
89
  }
33
90
  }
@@ -1,5 +1,24 @@
1
1
  import { Answerable, Expectation } from '@serenity-js/core';
2
2
 
3
+ /**
4
+ * Creates an {@apilink Expectation|expectation} that is met when the actual `string` value
5
+ * starts with the resolved value of `expected`.
6
+ *
7
+ * ## Ensuring that a given string starts with an expected substring
8
+ *
9
+ * ```ts
10
+ * import { actorCalled } from '@serenity-js/core'
11
+ * import { Ensure, startsWith } from '@serenity-js/assertions'
12
+ *
13
+ * await actorCalled('Ester').attemptsTo(
14
+ * Ensure.that('Hello World!', startsWith('Hello')),
15
+ * )
16
+ * ```
17
+ *
18
+ * @param expected
19
+ *
20
+ * @group Expectations
21
+ */
3
22
  export function startsWith(expected: Answerable<string>): Expectation<string> {
4
23
  return Expectation.thatActualShould<string, string>('start with', expected)
5
24
  .soThat((actualValue, expectedValue) => actualValue.startsWith(expectedValue));
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './Ensure';
2
2
  export * from './expectations';
3
- export { Check, Expectation } from '@serenity-js/core'; // re-exported to avoid breaking backwards compatibility with tests using 2.24.1
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "outDir": "lib",
5
+ "rootDir": "src"
6
+ },
7
+ "include": [
8
+ "src/**/*.ts"
9
+ ]
10
+ }
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig",
3
- "include": [
4
- "src/**/*.ts",
5
- "spec/**/*.ts"
6
- ],
7
- "exclude": [
8
- "node_modules"
9
- ]
10
- }