Skip to content

Commit b55d3a1

Browse files
authored
added an error if implementation of sorting function was not found in memory (#18)
1 parent 8faa28a commit b55d3a1

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

CHANGELOG.MD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to the "@qavajs/steps-memory" will be documented in this fil
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7+
## [0.13.0]
8+
- added an error if implementation of sorting function was not found in memory
9+
710
## [0.12.0]
811
- added validation step with parameter in form of data table array
912

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@cucumber/cucumber": "^9.1.2",
2525
"@qavajs/cli": "^0.0.24",
2626
"@qavajs/console-formatter": "^0.2.1",
27-
"@qavajs/memory": "^1.4.1",
27+
"@qavajs/memory": "^1.5.1",
2828
"@qavajs/xunit-formatter": "^0.0.4",
2929
"@types/chai": "^4.3.5",
3030
"ts-node": "^10.9.1",

src/validation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Then(
7272
* Verify that array is sorted by
7373
* @param {string} arr - memory key of array
7474
* @param {string} comparator - memory key of sort comparator function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description
75+
* Important: This module does not include implementation of sorting function,
76+
* as it may have various implementations for different types of compared data
7577
* @example I expect '$arr' array to be sorted by '$ascending'
7678
*/
7779
Then(
@@ -80,6 +82,7 @@ Then(
8082
const array: Array<any> = await getValue(arr);
8183
if (!Array.isArray(array)) throw new Error(`'${arr}' is not an array`);
8284
const comparatorFn: (a: any, b: any) => number = await getValue(comparator);
85+
if (typeof comparatorFn !== 'function') throw new Error(`'${comparator}' is not implemented`);
8386
const arrayCopy: Array<any> = [...array];
8487
arrayCopy.sort(comparatorFn);
8588
const validation: Function = getValidation('to deeply equal');

test-e2e/features/memory.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Memory
55
Then I expect '$result' to be equal '33'
66

77
Scenario: save result of sync computed to memory
8-
When I save "$getString()" to memory as 'string1'
8+
When I save "$getComputedString()" to memory as 'string1'
99
Then I expect '$string1' to be equal 'I was computed'
1010

1111
Scenario: save result of async computed to memory

test-e2e/memory/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ export default class Memory {
22

33
arr = [1, 2, 3, 4, 5];
44
reverseArr = [5, 4, 3, 2, 1];
5-
getString = function (): string {
5+
getComputedString = function (): string {
66
return 'I was computed';
77
};
88

99
getStringAsync = function (): Promise<string> {
10-
return new Promise((resolve, reject) => {
10+
return new Promise((resolve) => {
1111
setTimeout(() => {
1212
resolve('I was computed async');
1313
}, 50);

0 commit comments

Comments
 (0)