@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.
- package/CHANGELOG.md +51 -1913
- package/README.md +10 -8
- package/lib/Ensure.d.ts +56 -77
- package/lib/Ensure.d.ts.map +1 -0
- package/lib/Ensure.js +62 -90
- package/lib/Ensure.js.map +1 -1
- package/lib/expectations/and.d.ts +22 -1
- package/lib/expectations/and.d.ts.map +1 -0
- package/lib/expectations/and.js +26 -6
- package/lib/expectations/and.js.map +1 -1
- package/lib/expectations/contain.d.ts +26 -1
- package/lib/expectations/contain.d.ts.map +1 -0
- package/lib/expectations/contain.js +25 -1
- package/lib/expectations/contain.js.map +1 -1
- package/lib/expectations/containAtLeastOneItemThat.d.ts +23 -1
- package/lib/expectations/containAtLeastOneItemThat.d.ts.map +1 -0
- package/lib/expectations/containAtLeastOneItemThat.js +37 -9
- package/lib/expectations/containAtLeastOneItemThat.js.map +1 -1
- package/lib/expectations/containItemsWhereEachItem.d.ts +23 -1
- package/lib/expectations/containItemsWhereEachItem.d.ts.map +1 -0
- package/lib/expectations/containItemsWhereEachItem.js +37 -9
- package/lib/expectations/containItemsWhereEachItem.js.map +1 -1
- package/lib/expectations/endsWith.d.ts +20 -0
- package/lib/expectations/endsWith.d.ts.map +1 -0
- package/lib/expectations/endsWith.js +19 -0
- package/lib/expectations/endsWith.js.map +1 -1
- package/lib/expectations/equals.d.ts +26 -0
- package/lib/expectations/equals.d.ts.map +1 -0
- package/lib/expectations/equals.js +25 -0
- package/lib/expectations/equals.js.map +1 -1
- package/lib/expectations/includes.d.ts +20 -0
- package/lib/expectations/includes.d.ts.map +1 -0
- package/lib/expectations/includes.js +19 -0
- package/lib/expectations/includes.js.map +1 -1
- package/lib/expectations/index.d.ts +3 -0
- package/lib/expectations/index.d.ts.map +1 -0
- package/lib/expectations/index.js +7 -1
- package/lib/expectations/index.js.map +1 -1
- package/lib/expectations/isAfter.d.ts +40 -0
- package/lib/expectations/isAfter.d.ts.map +1 -0
- package/lib/expectations/isAfter.js +39 -0
- package/lib/expectations/isAfter.js.map +1 -1
- package/lib/expectations/isBefore.d.ts +40 -0
- package/lib/expectations/isBefore.d.ts.map +1 -0
- package/lib/expectations/isBefore.js +39 -0
- package/lib/expectations/isBefore.js.map +1 -1
- package/lib/expectations/isCloseTo.d.ts +24 -0
- package/lib/expectations/isCloseTo.d.ts.map +1 -0
- package/lib/expectations/isCloseTo.js +57 -0
- package/lib/expectations/isCloseTo.js.map +1 -0
- package/lib/expectations/isFalse.d.ts +19 -0
- package/lib/expectations/isFalse.d.ts.map +1 -0
- package/lib/expectations/isFalse.js +18 -0
- package/lib/expectations/isFalse.js.map +1 -1
- package/lib/expectations/isGreaterThan.d.ts +43 -0
- package/lib/expectations/isGreaterThan.d.ts.map +1 -0
- package/lib/expectations/isGreaterThan.js +42 -0
- package/lib/expectations/isGreaterThan.js.map +1 -1
- package/lib/expectations/isLessThan.d.ts +43 -0
- package/lib/expectations/isLessThan.d.ts.map +1 -0
- package/lib/expectations/isLessThan.js +42 -0
- package/lib/expectations/isLessThan.js.map +1 -1
- package/lib/expectations/isPresent.d.ts +64 -0
- package/lib/expectations/isPresent.d.ts.map +1 -0
- package/lib/expectations/isPresent.js +99 -0
- package/lib/expectations/isPresent.js.map +1 -0
- package/lib/expectations/isTrue.d.ts +19 -0
- package/lib/expectations/isTrue.d.ts.map +1 -0
- package/lib/expectations/isTrue.js +18 -0
- package/lib/expectations/isTrue.js.map +1 -1
- package/lib/expectations/matches.d.ts +21 -1
- package/lib/expectations/matches.d.ts.map +1 -0
- package/lib/expectations/matches.js +19 -0
- package/lib/expectations/matches.js.map +1 -1
- package/lib/expectations/not.d.ts +23 -1
- package/lib/expectations/not.d.ts.map +1 -0
- package/lib/expectations/not.js +30 -10
- package/lib/expectations/not.js.map +1 -1
- package/lib/expectations/or.d.ts +22 -1
- package/lib/expectations/or.d.ts.map +1 -0
- package/lib/expectations/or.js +39 -14
- package/lib/expectations/or.js.map +1 -1
- package/lib/expectations/property.d.ts +61 -1
- package/lib/expectations/property.d.ts.map +1 -0
- package/lib/expectations/property.js +66 -10
- package/lib/expectations/property.js.map +1 -1
- package/lib/expectations/startsWith.d.ts +20 -0
- package/lib/expectations/startsWith.d.ts.map +1 -0
- package/lib/expectations/startsWith.js +19 -0
- package/lib/expectations/startsWith.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -5
- package/lib/index.js.map +1 -1
- package/package.json +16 -40
- package/src/Ensure.ts +75 -101
- package/src/expectations/and.ts +39 -18
- package/src/expectations/contain.ts +26 -2
- package/src/expectations/containAtLeastOneItemThat.ts +59 -14
- package/src/expectations/containItemsWhereEachItem.ts +59 -14
- package/src/expectations/endsWith.ts +19 -0
- package/src/expectations/equals.ts +25 -0
- package/src/expectations/includes.ts +19 -0
- package/src/expectations/index.ts +2 -0
- package/src/expectations/isAfter.ts +39 -0
- package/src/expectations/isBefore.ts +39 -0
- package/src/expectations/isCloseTo.ts +66 -0
- package/src/expectations/isFalse.ts +19 -1
- package/src/expectations/isGreaterThan.ts +42 -0
- package/src/expectations/isLessThan.ts +42 -0
- package/src/expectations/isPresent.ts +107 -0
- package/src/expectations/isTrue.ts +19 -1
- package/src/expectations/matches.ts +20 -1
- package/src/expectations/not.ts +36 -15
- package/src/expectations/or.ts +49 -26
- package/src/expectations/property.ts +78 -21
- package/src/expectations/startsWith.ts +19 -0
- package/src/index.ts +0 -1
- package/tsconfig.build.json +10 -0
- package/tsconfig.eslint.json +0 -10
|
@@ -1,33 +1,90 @@
|
|
|
1
|
-
import { AnswersQuestions, Expectation, ExpectationMet, ExpectationNotMet
|
|
2
|
-
import { formatted } from '@serenity-js/core/lib/io';
|
|
1
|
+
import { Answerable, AnswersQuestions, Expectation, ExpectationMet, ExpectationNotMet } from '@serenity-js/core';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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<
|
|
72
|
+
class HasProperty<Actual extends object, PropertyName extends keyof Actual> extends Expectation<Actual> {
|
|
15
73
|
constructor(
|
|
16
|
-
private readonly propertyName:
|
|
17
|
-
|
|
74
|
+
private readonly propertyName: PropertyName,
|
|
75
|
+
expectation: Expectation<Actual[PropertyName]>,
|
|
18
76
|
) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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