{"id":31,"date":"2019-06-17T10:04:28","date_gmt":"2019-06-17T10:04:28","guid":{"rendered":"https:\/\/www.bddtesting.com\/?page_id=31"},"modified":"2019-06-17T10:18:00","modified_gmt":"2019-06-17T10:18:00","slug":"react-behavior-driven-development-r-bdd","status":"publish","type":"page","link":"https:\/\/www.bddtesting.com\/react-behavior-driven-development-r-bdd\/","title":{"rendered":"React Behavior Driven Development (R-BDD)"},"content":{"rendered":"\n
The examples in this article are created with:<\/p>\n\n\n\n
The examples are available for download<\/a>.<\/p>\n\n\n\n What is BDD and Cucumber?<\/strong><\/p>\n\n\n\n Behaviour-Driven Development (BDD) is a collaborative approach to software development that bridges the communication gap between business and IT. BDD helps teams communicate requirements with more precision, discover defects early and produce software that remains maintainable over time.<\/p><\/blockquote>\n\n\n\n It helps teams create business requirements that can be understood by the whole team. Specifying examples uncovers misunderstanding people might not even be aware of. Teams that practice BDD focus on preventing defects rather than finding them. This leads to less rework and quicker time to market.<\/p><\/blockquote>\n\n\n\n The two main practices in the BDD approach are discovery workshops, which bridge the communication gap between business and IT, and executable specifications.<\/p><\/blockquote>\n\n\n\n \u2014 Cucumber\u200a\u2014<\/em>\u200aBDD Tutorial<\/em><\/a><\/p>\n\n\n\n Cucumber is a tool that supports Behaviour-Driven Development(BDD).<\/p><\/blockquote>\n\n\n\n Cucumber reads executable specifications written in plain text and validates that the software does what those specifications say. The specifications consists of multiple examples, or scenarios. \u2014 Cucumber\u200a\u2014\u200a<\/em>Introduction<\/em><\/a><\/p>\n\n\n\n First Reactions<\/strong><\/p>\n\n\n\n My first reaction when reading about BDD was, \u201cIt sounds like yet another business consulting word-soup.\u201d<\/p>\n\n\n\n Also, I felt that BDD was redundant as I already have embraced integration testing, i.e., testing features, not modules. See Revisiting React Testing in 2019<\/em><\/a>for more on that.<\/p>\n\n\n\n Finally, going through the Cucumber <\/em>10 Minute Tutorial<\/em><\/a> (JavaScript),<\/em> it was not clear how I could integrate the cucumber<\/em> library into the Jest<\/em> testing framework that I have become accustomed to.<\/p>\n\n\n\n Enter Jest Cucumber<\/strong><\/p>\n\n\n\n Just about when I was about to give up on BDD and Cucumber<\/em>, I stumbled upon Jest Cucumber<\/em><\/a>.<\/p>\n\n\n\n jest-cucumber is an alternative to Cucumber.js that runs on top on Jest. Instead of using describe and it blocks, you instead write a Jest test for each scenario, and then define Given, When, and Then step definitions inside of your Jest tests. jest-cucumber then allows you to link these Jest tests to your feature files and ensure that they always stay in sync.<\/p><\/blockquote>\n\n\n\n
\u2026
In order for Cucumber to understand the scenarios, they must follow some basic syntax rules, called Gherkin.<\/p><\/blockquote>\n\n\n\n