Use sinon.js to easily write stubs for your BDD features in cucumber.js

While using BDD to optimize our current teams workflow there is all kinds of stuff we learn. BDD really drives better software. One of first lessons learned was to separate concerns and that Cucumber.js is certainly not limited to automated testing using selenium etc.

Good learning’s about that came from Jan Stenberg article about BDD/cucumber and for me it helped to reset the reasons why with started walking on this path in the first place.

Currently we are building a dashboard to monitor the health of ad delivery. In the beginning we had a lot of business rules in our Polymer front-end however the BDD features we had described drove naturally towards a more back-end centered application.

Suddenly our development cycle was on steroids, because the only selenium tests we had were limited to some basic behavior when fed a data structure. Our ‘real’ features could now be executed on the API to validate the expected behavior.

The thing I would to share with you today is the hook we made for stubbing some our interfaces.

Now in your step definitions you can stub the interface without worrying about restoring your stubs. All sinon.js stubs are wrapped into this small hooks.

Hope you will find this useful. We certainly do!