|
| 1 | +--- |
| 2 | +permalink: /helpers/SoftExpectHelper |
| 3 | +editLink: false |
| 4 | +sidebar: auto |
| 5 | +title: SoftExpectHelper |
| 6 | +--- |
| 7 | + |
| 8 | +<!-- Generated by documentation.js. Update this documentation by updating the source code. --> |
| 9 | + |
| 10 | +## SoftAssertHelper |
| 11 | + |
| 12 | +**Extends ExpectHelper** |
| 13 | + |
| 14 | +SoftAssertHelper is a utility class for performing soft assertions. |
| 15 | +Unlike traditional assertions that stop the execution on failure, |
| 16 | +soft assertions allow the execution to continue and report all failures at the end. |
| 17 | + |
| 18 | +### Examples |
| 19 | + |
| 20 | +Zero-configuration when paired with other helpers like REST, Playwright: |
| 21 | + |
| 22 | +```js |
| 23 | +// inside codecept.conf.js |
| 24 | +{ |
| 25 | + helpers: { |
| 26 | + Playwright: {...}, |
| 27 | + SoftExpectHelper: {}, |
| 28 | + } |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +```js |
| 33 | +// in scenario |
| 34 | +I.softExpectEqual('a', 'b') |
| 35 | +I.flushSoftAssertions() // Throws an error if any soft assertions have failed. The error message contains all the accumulated failures. |
| 36 | +``` |
| 37 | + |
| 38 | +## Methods |
| 39 | + |
| 40 | +### flushSoftAssertions |
| 41 | + |
| 42 | +Throws an error if any soft assertions have failed. |
| 43 | +The error message contains all the accumulated failures. |
| 44 | + |
| 45 | +- Throws **[Error][1]** If there are any soft assertion failures. |
| 46 | + |
| 47 | +### softAssert |
| 48 | + |
| 49 | +Performs a soft assertion by executing the provided assertion function. |
| 50 | +If the assertion fails, the error is caught and stored without halting the execution. |
| 51 | + |
| 52 | +#### Parameters |
| 53 | + |
| 54 | +- `assertionFn` **[Function][2]** The assertion function to execute. |
| 55 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 56 | + |
| 57 | +### softExpectAbove |
| 58 | + |
| 59 | +Softly asserts that the target data is above a specified value. |
| 60 | + |
| 61 | +#### Parameters |
| 62 | + |
| 63 | +- `targetData` **any** The data to check. |
| 64 | +- `aboveThan` **any** The value that the target data should be above. |
| 65 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 66 | + |
| 67 | +### softExpectBelow |
| 68 | + |
| 69 | +Softly asserts that the target data is below a specified value. |
| 70 | + |
| 71 | +#### Parameters |
| 72 | + |
| 73 | +- `targetData` **any** The data to check. |
| 74 | +- `belowThan` **any** The value that the target data should be below. |
| 75 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 76 | + |
| 77 | +### softExpectContain |
| 78 | + |
| 79 | +Softly asserts that a value contains the expected value. |
| 80 | + |
| 81 | +#### Parameters |
| 82 | + |
| 83 | +- `actualValue` **any** The actual value. |
| 84 | +- `expectedValueToContain` **any** The value that should be contained within the actual value. |
| 85 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 86 | + |
| 87 | +### softExpectDeepEqual |
| 88 | + |
| 89 | +Softly asserts that two values are deeply equal. |
| 90 | + |
| 91 | +#### Parameters |
| 92 | + |
| 93 | +- `actualValue` **any** The actual value. |
| 94 | +- `expectedValue` **any** The expected value. |
| 95 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 96 | + |
| 97 | +### softExpectDeepEqualExcluding |
| 98 | + |
| 99 | +Softly asserts that two objects are deeply equal, excluding specified fields. |
| 100 | + |
| 101 | +#### Parameters |
| 102 | + |
| 103 | +- `actualValue` **[Object][4]** The actual object. |
| 104 | +- `expectedValue` **[Object][4]** The expected object. |
| 105 | +- `fieldsToExclude` **[Array][5]<[string][3]>** The fields to exclude from the comparison. |
| 106 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 107 | + |
| 108 | +### softExpectDeepIncludeMembers |
| 109 | + |
| 110 | +Softly asserts that an array (superset) deeply includes all members of another array (set). |
| 111 | + |
| 112 | +#### Parameters |
| 113 | + |
| 114 | +- `superset` **[Array][5]** The array that should contain the expected members. |
| 115 | +- `set` **[Array][5]** The array with members that should be included. |
| 116 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 117 | + |
| 118 | +### softExpectDeepMembers |
| 119 | + |
| 120 | +Softly asserts that two arrays have deep equality, considering members in any order. |
| 121 | + |
| 122 | +#### Parameters |
| 123 | + |
| 124 | +- `actualValue` **[Array][5]** The actual array. |
| 125 | +- `expectedValue` **[Array][5]** The expected array. |
| 126 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 127 | + |
| 128 | +### softExpectEmpty |
| 129 | + |
| 130 | +Softly asserts that the target data is empty. |
| 131 | + |
| 132 | +#### Parameters |
| 133 | + |
| 134 | +- `targetData` **any** The data to check. |
| 135 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 136 | + |
| 137 | +### softExpectEndsWith |
| 138 | + |
| 139 | +Softly asserts that a value ends with the expected value. |
| 140 | + |
| 141 | +#### Parameters |
| 142 | + |
| 143 | +- `actualValue` **any** The actual value. |
| 144 | +- `expectedValueToEndWith` **any** The value that the actual value should end with. |
| 145 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 146 | + |
| 147 | +### softExpectEqual |
| 148 | + |
| 149 | +Softly asserts that two values are equal. |
| 150 | + |
| 151 | +#### Parameters |
| 152 | + |
| 153 | +- `actualValue` **any** The actual value. |
| 154 | +- `expectedValue` **any** The expected value. |
| 155 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 156 | + |
| 157 | +### softExpectEqualIgnoreCase |
| 158 | + |
| 159 | +Softly asserts that two values are equal, ignoring case. |
| 160 | + |
| 161 | +#### Parameters |
| 162 | + |
| 163 | +- `actualValue` **[string][3]** The actual string value. |
| 164 | +- `expectedValue` **[string][3]** The expected string value. |
| 165 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 166 | + |
| 167 | +### softExpectFalse |
| 168 | + |
| 169 | +Softly asserts that the target data is false. |
| 170 | + |
| 171 | +#### Parameters |
| 172 | + |
| 173 | +- `targetData` **any** The data to check. |
| 174 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 175 | + |
| 176 | +### softExpectHasAProperty |
| 177 | + |
| 178 | +Softly asserts that the target data has a property with the specified name. |
| 179 | + |
| 180 | +#### Parameters |
| 181 | + |
| 182 | +- `targetData` **any** The data to check. |
| 183 | +- `propertyName` **[string][3]** The property name to check for. |
| 184 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 185 | + |
| 186 | +### softExpectHasProperty |
| 187 | + |
| 188 | +Softly asserts that the target data has the specified property. |
| 189 | + |
| 190 | +#### Parameters |
| 191 | + |
| 192 | +- `targetData` **any** The data to check. |
| 193 | +- `propertyName` **[string][3]** The property name to check for. |
| 194 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion |
| 195 | + fails. |
| 196 | + |
| 197 | +### softExpectJsonSchema |
| 198 | + |
| 199 | +Softly asserts that the target data matches the given JSON schema. |
| 200 | + |
| 201 | +#### Parameters |
| 202 | + |
| 203 | +- `targetData` **any** The data to validate. |
| 204 | +- `jsonSchema` **[Object][4]** The JSON schema to validate against. |
| 205 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 206 | + |
| 207 | +### softExpectJsonSchemaUsingAJV |
| 208 | + |
| 209 | +Softly asserts that the target data matches the given JSON schema using AJV. |
| 210 | + |
| 211 | +#### Parameters |
| 212 | + |
| 213 | +- `targetData` **any** The data to validate. |
| 214 | +- `jsonSchema` **[Object][4]** The JSON schema to validate against. |
| 215 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 216 | +- `ajvOptions` **[Object][4]** Options to pass to AJV. |
| 217 | + |
| 218 | +### softExpectLengthAboveThan |
| 219 | + |
| 220 | +Softly asserts that the length of the target data is above a specified value. |
| 221 | + |
| 222 | +#### Parameters |
| 223 | + |
| 224 | +- `targetData` **any** The data to check. |
| 225 | +- `lengthAboveThan` **[number][6]** The length that the target data should be above. |
| 226 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 227 | + |
| 228 | +### softExpectLengthBelowThan |
| 229 | + |
| 230 | +Softly asserts that the length of the target data is below a specified value. |
| 231 | + |
| 232 | +#### Parameters |
| 233 | + |
| 234 | +- `targetData` **any** The data to check. |
| 235 | +- `lengthBelowThan` **[number][6]** The length that the target data should be below. |
| 236 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 237 | + |
| 238 | +### softExpectLengthOf |
| 239 | + |
| 240 | +Softly asserts that the target data has a specified length. |
| 241 | + |
| 242 | +#### Parameters |
| 243 | + |
| 244 | +- `targetData` **any** The data to check. |
| 245 | +- `length` **[number][6]** The expected length. |
| 246 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 247 | + |
| 248 | +### softExpectMatchesPattern |
| 249 | + |
| 250 | +Softly asserts that a value matches the expected pattern. |
| 251 | + |
| 252 | +#### Parameters |
| 253 | + |
| 254 | +- `actualValue` **any** The actual value. |
| 255 | +- `expectedPattern` **any** The pattern the value should match. |
| 256 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 257 | + |
| 258 | +### softExpectNotContain |
| 259 | + |
| 260 | +Softly asserts that a value does not contain the expected value. |
| 261 | + |
| 262 | +#### Parameters |
| 263 | + |
| 264 | +- `actualValue` **any** The actual value. |
| 265 | +- `expectedValueToNotContain` **any** The value that should not be contained within the actual value. |
| 266 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 267 | + |
| 268 | +### softExpectNotDeepEqual |
| 269 | + |
| 270 | +Softly asserts that two values are not deeply equal. |
| 271 | + |
| 272 | +#### Parameters |
| 273 | + |
| 274 | +- `actualValue` **any** The actual value. |
| 275 | +- `expectedValue` **any** The expected value. |
| 276 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 277 | + |
| 278 | +### softExpectNotEndsWith |
| 279 | + |
| 280 | +Softly asserts that a value does not end with the expected value. |
| 281 | + |
| 282 | +#### Parameters |
| 283 | + |
| 284 | +- `actualValue` **any** The actual value. |
| 285 | +- `expectedValueToNotEndWith` **any** The value that the actual value should not end with. |
| 286 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 287 | + |
| 288 | +### softExpectNotEqual |
| 289 | + |
| 290 | +Softly asserts that two values are not equal. |
| 291 | + |
| 292 | +#### Parameters |
| 293 | + |
| 294 | +- `actualValue` **any** The actual value. |
| 295 | +- `expectedValue` **any** The expected value. |
| 296 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 297 | + |
| 298 | +### softExpectNotStartsWith |
| 299 | + |
| 300 | +Softly asserts that a value does not start with the expected value. |
| 301 | + |
| 302 | +#### Parameters |
| 303 | + |
| 304 | +- `actualValue` **any** The actual value. |
| 305 | +- `expectedValueToNotStartWith` **any** The value that the actual value should not start with. |
| 306 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 307 | + |
| 308 | +### softExpectStartsWith |
| 309 | + |
| 310 | +Softly asserts that a value starts with the expected value. |
| 311 | + |
| 312 | +#### Parameters |
| 313 | + |
| 314 | +- `actualValue` **any** The actual value. |
| 315 | +- `expectedValueToStartWith` **any** The value that the actual value should start with. |
| 316 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 317 | + |
| 318 | +### softExpectToBeA |
| 319 | + |
| 320 | +Softly asserts that the target data is of a specific type. |
| 321 | + |
| 322 | +#### Parameters |
| 323 | + |
| 324 | +- `targetData` **any** The data to check. |
| 325 | +- `type` **[string][3]** The expected type (e.g., 'string', 'number'). |
| 326 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 327 | + |
| 328 | +### softExpectToBeAn |
| 329 | + |
| 330 | +Softly asserts that the target data is of a specific type (alternative for articles). |
| 331 | + |
| 332 | +#### Parameters |
| 333 | + |
| 334 | +- `targetData` **any** The data to check. |
| 335 | +- `type` **[string][3]** The expected type (e.g., 'string', 'number'). |
| 336 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 337 | + |
| 338 | +### softExpectTrue |
| 339 | + |
| 340 | +Softly asserts that the target data is true. |
| 341 | + |
| 342 | +#### Parameters |
| 343 | + |
| 344 | +- `targetData` **any** The data to check. |
| 345 | +- `customErrorMsg` **[string][3]** A custom error message to display if the assertion fails. |
| 346 | + |
| 347 | +[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error |
| 348 | + |
| 349 | +[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function |
| 350 | + |
| 351 | +[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String |
| 352 | + |
| 353 | +[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object |
| 354 | + |
| 355 | +[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array |
| 356 | + |
| 357 | +[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number |
0 commit comments