Reputation: 55769
I am using the Yadda BDD JavaScript library (https://github.com/acuminous/yadda).
I want to write a step definition that returns a value. How can I do so in such a way that the value is passed onto the next step?
library.given('I get a value', function() {
// Get the value
var value = getValue();
//...
and supply to the next step - how?
});
Usage:
Given I get a value
When I do something with this value # How can I refer to this value?
Upvotes: 2
Views: 262
Reputation: 968
There are two ways to do this in Yadda.
Store the value created in your "Given" step as a variable on the step library, then reference it in the "When" step. This approach is simple but has the drawback that the library now maintains state. It also only works if steps are held in the same library
When you invoke Yadda the 2nd (optional) argument can be a object. This will be passed to all steps, irrespective of what library they are defined in. The steps are bound to this object when they are executed. See https://github.com/acuminous/yadda/blob/master/examples/context/test.js and https://acuminous.gitbooks.io/yadda-user-guide/content/en/usage/managing-state.html for more information
Upvotes: 2