Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
:pencil: - chore
:microscope: - experimental

## [3.3.0]
- :rocket: added `to satisfy` validation to verify user-defined expectation provided as predicate
```Gherkin
Then I expect '$value' to satisfy '$either(1, 2)'
```
where `$either` is a function
```typescript
function either(...expected) {
return function (actual) {
return expected.includes(actual)
}
}
```

## [3.2.0]
- :rocket: Added capability to provide _defaultResolver_ to define default logic to identify element
```typescript
Expand Down
60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qavajs/playwright",
"version": "3.2.0",
"version": "3.3.0",
"description": "steps to interact with playwright",
"main": "./index.js",
"scripts": {
Expand All @@ -26,14 +26,14 @@
"homepage": "https://github.com/qavajs/playwright#readme",
"devDependencies": {
"@types/express": "^5.0.3",
"@types/node": "^24.1.0",
"electron": "^37.2.4",
"@types/node": "^24.3.0",
"electron": "^37.3.1",
"express": "^5.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
"typescript": "^5.9.2"
},
"dependencies": {
"@playwright/test": "^1.54.1",
"@playwright/test": "^1.55.0",
"@qavajs/playwright-runner-adapter": "^1.4.3",
"@qavajs/memory": "^1.10.2"
}
Expand Down
2 changes: 1 addition & 1 deletion src/parameterTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function transformString(fn: (value: string) => any) {

defineParameterType({
name: 'validation',
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)?)/,
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)?)/,
transformer: condition => {
const validation: Validation = function (AR: any, ER: any) {
return valueExpect(AR, ER, condition);
Expand Down
14 changes: 14 additions & 0 deletions src/validationExpect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const expect = base.extend({
pass
}
},
toSatisfy(actual: any, predicate: any) {
const pass = predicate(actual);
return {
message: () => `expected ${actual} ${pass ? 'not ': ''}to satisfy ${this.utils.printReceived(predicate)}`,
pass
}
}
});

export const validations = {
Expand All @@ -35,6 +42,8 @@ export const validations = {
HAVE_TYPE: 'have type',
INCLUDE_MEMBERS: 'include member',
MATCH_SCHEMA: 'match schema',
SATISFY: 'satisfy',
CASE_INSENSITIVE_EQUAL: 'case insensitive equal',
};

const isClause = '(?:is |do |does |to )?';
Expand Down Expand Up @@ -94,6 +103,11 @@ const expects = {
[validations.HAVE_TYPE]:
// @ts-ignore
({ expected, actual, reverse, poll, soft }: ExpectOptions) => expectValue({ expected, reverse, poll, soft }).toHaveType(actual),
[validations.CASE_INSENSITIVE_EQUAL]:
({ expected, actual, reverse, poll, soft }: ExpectOptions) => expectValue({ expected: expected.toLowerCase(), reverse, poll, soft }).toEqual(actual.toLowerCase()),
[validations.SATISFY]:
// @ts-ignore
({ expected, actual, reverse, poll, soft }: ExpectOptions) => expectValue({ expected, reverse, poll, soft }).toSatisfy(actual),
};

export function valueExpect(
Expand Down
21 changes: 21 additions & 0 deletions test-e2e/features/validations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,24 @@ Feature: validations
Then I expect '3' not to equal all of:
| 1 |
| $two |

Scenario Outline: validation type (<validation>)
When I expect '<argument1>' <validation> '<argument2>'

Examples:
| argument1 | argument2 | validation |
| 1 | 1 | to equal |
| 1 | 2 | to not equal |
| test | tes | to contain |
| 1 | 1 | to strictly equal |
| $js({ a: 1 }) | $js({ a: 1 }) | to deeply equal |
| Test | test | to case insensitive equal |
# | $js([1, 2, 3]) | $js([3]) | to include members |
# | $js([3, 2, 1]) | $js([1, 2, 3]) | to have members |
# | $js({ a: 1 }) | a | to have property |
| $js(2) | $js(1) | to be greater than |
| $js(1) | $js(2) | to be less than |
| test | tes. | to match |
| $js("Test") | string | to have type |
# | $js({ a: 1 }) | $js({ type: "object", properties: { a: { type: "number" } } }) | to match schema |
| 1 | $js(arg => ["1","2"].includes(arg)) | to satisfy |