Skip to content

Commit fb20520

Browse files
Merge pull request #28 from qavajs/satisfy
added `to satisfy` validation to verify user-defined expectation provided as predicate
2 parents 9331fc9 + 96d34fa commit fb20520

File tree

6 files changed

+85
-36
lines changed

6 files changed

+85
-36
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1010
:pencil: - chore
1111
:microscope: - experimental
1212

13+
## [3.3.0]
14+
- :rocket: added `to satisfy` validation to verify user-defined expectation provided as predicate
15+
```Gherkin
16+
Then I expect '$value' to satisfy '$either(1, 2)'
17+
```
18+
where `$either` is a function
19+
```typescript
20+
function either(...expected) {
21+
return function (actual) {
22+
return expected.includes(actual)
23+
}
24+
}
25+
```
26+
1327
## [3.2.0]
1428
- :rocket: Added capability to provide _defaultResolver_ to define default logic to identify element
1529
```typescript

package-lock.json

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qavajs/playwright",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "steps to interact with playwright",
55
"main": "./index.js",
66
"scripts": {
@@ -26,14 +26,14 @@
2626
"homepage": "https://github.com/qavajs/playwright#readme",
2727
"devDependencies": {
2828
"@types/express": "^5.0.3",
29-
"@types/node": "^24.1.0",
30-
"electron": "^37.2.4",
29+
"@types/node": "^24.3.0",
30+
"electron": "^37.3.1",
3131
"express": "^5.1.0",
3232
"ts-node": "^10.9.2",
33-
"typescript": "^5.8.3"
33+
"typescript": "^5.9.2"
3434
},
3535
"dependencies": {
36-
"@playwright/test": "^1.54.1",
36+
"@playwright/test": "^1.55.0",
3737
"@qavajs/playwright-runner-adapter": "^1.4.3",
3838
"@qavajs/memory": "^1.10.2"
3939
}

src/parameterTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function transformString(fn: (value: string) => any) {
1313

1414
defineParameterType({
1515
name: 'validation',
16-
regexp: /((?:is |do |does |to )?(not |to not )?(?:to )?(?:be )?(softly )?(equal|strictly equal|deeply equal|have member|match|contain|above|below|greater than|less than|have type)(?:s|es)?)/,
16+
regexp: /((?:is |do |does |to )?(not |to not )?(?:to )?(?:be )?(softly )?(equal|strictly equal|deeply equal|have member|match|contain|above|below|greater than|less than|have type|satisfy|case insensitive equal)(?:s|es)?)/,
1717
transformer: condition => {
1818
const validation: Validation = function (AR: any, ER: any) {
1919
return valueExpect(AR, ER, condition);

src/validationExpect.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export const expect = base.extend({
1919
pass
2020
}
2121
},
22+
toSatisfy(actual: any, predicate: any) {
23+
const pass = predicate(actual);
24+
return {
25+
message: () => `expected ${actual} ${pass ? 'not ': ''}to satisfy ${this.utils.printReceived(predicate)}`,
26+
pass
27+
}
28+
}
2229
});
2330

2431
export const validations = {
@@ -35,6 +42,8 @@ export const validations = {
3542
HAVE_TYPE: 'have type',
3643
INCLUDE_MEMBERS: 'include member',
3744
MATCH_SCHEMA: 'match schema',
45+
SATISFY: 'satisfy',
46+
CASE_INSENSITIVE_EQUAL: 'case insensitive equal',
3847
};
3948

4049
const isClause = '(?:is |do |does |to )?';
@@ -94,6 +103,11 @@ const expects = {
94103
[validations.HAVE_TYPE]:
95104
// @ts-ignore
96105
({ expected, actual, reverse, poll, soft }: ExpectOptions) => expectValue({ expected, reverse, poll, soft }).toHaveType(actual),
106+
[validations.CASE_INSENSITIVE_EQUAL]:
107+
({ expected, actual, reverse, poll, soft }: ExpectOptions) => expectValue({ expected: expected.toLowerCase(), reverse, poll, soft }).toEqual(actual.toLowerCase()),
108+
[validations.SATISFY]:
109+
// @ts-ignore
110+
({ expected, actual, reverse, poll, soft }: ExpectOptions) => expectValue({ expected, reverse, poll, soft }).toSatisfy(actual),
97111
};
98112

99113
export function valueExpect(

test-e2e/features/validations.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,24 @@ Feature: validations
146146
Then I expect '3' not to equal all of:
147147
| 1 |
148148
| $two |
149+
150+
Scenario Outline: validation type (<validation>)
151+
When I expect '<argument1>' <validation> '<argument2>'
152+
153+
Examples:
154+
| argument1 | argument2 | validation |
155+
| 1 | 1 | to equal |
156+
| 1 | 2 | to not equal |
157+
| test | tes | to contain |
158+
| 1 | 1 | to strictly equal |
159+
| $js({ a: 1 }) | $js({ a: 1 }) | to deeply equal |
160+
| Test | test | to case insensitive equal |
161+
# | $js([1, 2, 3]) | $js([3]) | to include members |
162+
# | $js([3, 2, 1]) | $js([1, 2, 3]) | to have members |
163+
# | $js({ a: 1 }) | a | to have property |
164+
| $js(2) | $js(1) | to be greater than |
165+
| $js(1) | $js(2) | to be less than |
166+
| test | tes. | to match |
167+
| $js("Test") | string | to have type |
168+
# | $js({ a: 1 }) | $js({ type: "object", properties: { a: { type: "number" } } }) | to match schema |
169+
| 1 | $js(arg => ["1","2"].includes(arg)) | to satisfy |

0 commit comments

Comments
 (0)