From 0a310417e390436f80ef01f47b9d5a8a9bccdbb0 Mon Sep 17 00:00:00 2001 From: Can Bezmen Date: Sun, 13 Jun 2021 10:36:40 +0300 Subject: [PATCH] Issue 127 * Fixed: Re-using step definitions not working (always undefined) --- docs/ReusingStepDefinitions.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/ReusingStepDefinitions.md b/docs/ReusingStepDefinitions.md index 3a297e6..ebe1a4c 100644 --- a/docs/ReusingStepDefinitions.md +++ b/docs/ReusingStepDefinitions.md @@ -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)); }); }; ``` @@ -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); }); }); ```