@@ -14,12 +14,41 @@ import { getValue } from './transformers';
1414Then (
1515 'I expect {string} {memoryValidation} {string}' ,
1616 async function ( value1 : string , validationType : string , value2 : string ) {
17- const val1 = await getValue ( value1 ) ;
18- const val2 = await getValue ( value2 ) ;
17+ const val1 : any = await getValue ( value1 ) ;
18+ const val2 : any = await getValue ( value2 ) ;
1919 const validation : Function = getValidation ( validationType ) ;
2020 validation ( val1 , val2 ) ;
2121} ) ;
2222
23+ /**
24+ * Verify that at least x elements in array pass validation
25+ * @param {string } arr - arr
26+ * @param {string } validation - validation
27+ * @param {string } expectedValue - expected value
28+ * @example I expect at least 1 element(s) in '$arr' array to be above '$expectedValue'
29+ * @example I expect at least 2 element(s) in '$arr' array to be above '50'
30+ */
31+ Then (
32+ 'I expect at least {int} elements in {string} array {memoryValidation} {string}' ,
33+ async function ( expectedNumber : number , arr : string , validationType : string , expectedValue : string ) {
34+ const array : Array < any > = await getValue ( arr ) ;
35+ const val : any = await getValue ( expectedValue ) ;
36+ const validation : Function = getValidation ( validationType ) ;
37+ const failCounter = { fail : 0 , pass : 0 } ;
38+ for ( const value of array ) {
39+ try {
40+ validation ( await value , val ) ;
41+ failCounter . pass ++ ;
42+ } catch ( err ) {
43+ failCounter . fail ++ ;
44+ }
45+ }
46+ if ( failCounter . pass < expectedNumber ) {
47+ throw new Error ( `Less than ${ expectedNumber } pass ${ validationType } verification` ) ;
48+ }
49+ }
50+ ) ;
51+
2352/**
2453 * Verify that every element in array satisfies validation against other value
2554 * @param {string } arr - arr
@@ -31,21 +60,37 @@ Then(
3160Then (
3261 'I expect every element in {string} array {memoryValidation} {string}' ,
3362 async function ( arr : string , validationType : string , expectedValue : string ) {
34- const array = await getValue ( arr ) ;
35- const val = await getValue ( expectedValue ) ;
63+ const array : Array < any > = await getValue ( arr ) ;
64+ const val : any = await getValue ( expectedValue ) ;
3665 const validation : Function = getValidation ( validationType ) ;
3766 for ( const value of array ) {
3867 validation ( await value , val ) ;
3968 }
4069 }
4170) ;
4271
72+ /**
73+ * Save result of math expression and save result to memory
74+ * @param expression - string expression
75+ * @param key - key to store value
76+ * @example When I save result of math expression '{$variable} + 42' as 'result'
77+ * @example When I save result of math expression '{$random()} * 100' as 'result'
78+ */
79+ When (
80+ 'I save result of math expression {string} as {string}' ,
81+ async function ( expression : string , key : string ) {
82+ const resolvedExpression : string = await getValue ( expression ) ;
83+ const exprFn = new Function ( 'return ' + resolvedExpression ) ;
84+ memory . setValue ( key , exprFn ) ;
85+ }
86+ ) ;
87+
4388/**
4489 * Save value to memory
4590 * @param {string } value
4691 * @param {string } key
4792 * @example I save 'value' to memory as 'key'
4893 */
49- When ( 'I save {string} to memory as {string}' , function ( value , key ) {
94+ When ( 'I save {string} to memory as {string}' , function ( value : string , key : string ) {
5095 memory . setValue ( key , value ) ;
5196} ) ;
0 commit comments