Skip to content

Commit 695a121

Browse files
authored
New/modify save step (#11)
* added capability of memory extraction for I save "" to memory as "" step
1 parent c139ded commit 695a121

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ When(
8787

8888
/**
8989
* Save value to memory
90-
* @param {string} value
91-
* @param {string} key
90+
* @param {string} alias - value to save or alias for previously saved value
91+
* @param {string} key - key to store value
9292
* @example I save 'value' to memory as 'key'
93+
* @example I save '$getRandomUser()' to memory as 'user'
9394
*/
94-
When('I save {string} to memory as {string}', function (value: string, key: string) {
95-
memory.setValue(key, value);
96-
});
95+
When(
96+
'I save {string} to memory as {string}',
97+
async function (alias: string, key: string) {
98+
const value: string = await memory.getValue(alias);
99+
memory.setValue(key, value);
100+
}
101+
);

test-e2e/features/memory.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ Feature: Memory
33
Scenario: math expression
44
When I save result of math expression '32 + 1' as 'result'
55
Then I expect '$result' to be equal '33'
6+
7+
Scenario: save result of sync computed to memory
8+
When I save "$getString()" to memory as 'string1'
9+
Then I expect '$string1' to be equal 'I was computed'
10+
11+
Scenario: save result of async computed to memory
12+
When I save "$getStringAsync()" to memory as 'string1'
13+
Then I expect '$string1' to be equal 'I was computed async'

test-e2e/memory/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
export default class Memory {
2+
getString = function(): string {
3+
return 'I was computed';
4+
};
5+
6+
getStringAsync = function(): Promise<string> {
7+
return new Promise((resolve, reject) => {
8+
setTimeout(() => {
9+
resolve('I was computed async');
10+
}, 50);
11+
});
12+
}
213
}

0 commit comments

Comments
 (0)