Skip to content

Commit

Permalink
Merge pull request #135 from cbezmen/master
Browse files Browse the repository at this point in the history
Issue #127
  • Loading branch information
bencompton authored Mar 25, 2024
2 parents 77617bd + 0a31041 commit 40f597c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions docs/ReusingStepDefinitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ If you need to re-use the same step definitions across multiple feature files, a
```javascript
// shared-steps.js

export const givenIHaveXDollarsInMyBankAccount = (given, account) => {
export const givenIHaveXDollarsInMyBankAccount = (given, accountCallback) => {
given(/I have \$(\d+) in my bank account/, balance => {
account.deposit(balance);
accountCallback().deposit(balance);
});
};

export const thenMyBalanceShouldBe = (then, account) => {
export const thenMyBalanceShouldBe = (then, accountCallback) => {
then(/my balance should be \$(\d+)/, balance => {
expect(account.balance).toBe(parseInt(balance));
expect(accountCallback().balance).toBe(parseInt(balance));
});
};
```
Expand All @@ -78,23 +78,23 @@ defineFeature(feature, test => {
});

test('Making a deposit', ({ given, when, then }) => {
givenIHaveXDollarsInMyBankAccount(given, myAccount);
givenIHaveXDollarsInMyBankAccount(given, () => myAccount);

when(/I deposit \$(\d+)/, deposit => {
myAccount.deposit(deposit);
});

thenMyBalanceShouldBe(then, myAccount);
thenMyBalanceShouldBe(then, () => myAccount);
});

test('Making a withdrawal', ({ given, when, then }) => {
givenIHaveXDollarsInMyBankAccount(given, myAccount);
givenIHaveXDollarsInMyBankAccount(given, () => myAccount);

when(/I withdraw \$(\d+)/, withdrawal => {
myAccount.withdraw(withdrawal);
});

thenMyBalanceShouldBe(then, myAccount);
thenMyBalanceShouldBe(then, () => myAccount);
});
});
```

0 comments on commit 40f597c

Please sign in to comment.