Learning Behavior-driven Development with JavaScript
eBook - ePub

Learning Behavior-driven Development with JavaScript

Enrique Amodeo

Share book
  1. 392 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Learning Behavior-driven Development with JavaScript

Enrique Amodeo

Book details
Book preview
Table of contents
Citations

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Learning Behavior-driven Development with JavaScript an online PDF/ePUB?
Yes, you can access Learning Behavior-driven Development with JavaScript by Enrique Amodeo in PDF and/or ePUB format, as well as other popular books in Computer Science & Web Services & APIs. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781784392642

Learning Behavior-driven Development with JavaScript


Table of Contents

Learning Behavior-driven Development with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Welcome to BDD
The test-first approach
The test-first cycle
Write a failing test
Make the test pass
Clean the code
Repeat!
Consequences of the test-first cycle
BDD versus TDD
Exploring unit testing
The structure of a test
Test doubles
What is a good test?
Summary
2. Automating Tests with Mocha, Chai, and Sinon
Node and NPM as development platforms
Installing Node and NPM
Configuring your project with NPM
Introducing Mocha
Useful options in Mocha
Our first test-first cycle
More expressive assertions with Chai
Working with the "should" interface
Red/Green/Refactor
Parameterized tests
Organizing your setup
Defining test scenarios
Test doubles with Sinon
Is it traditional TDD or BDD?
Welcome Sinon!
Integrating Sinon and Chai
Summary
3. Writing BDD Features
Introducing myCafé
Writing features
Displaying a customer's order
Tips for writing features
Starting to code the scenarios
Testing asynchronous features
Testing a callback-based API
Testing a promise-based API
Interlude – promises 101
Mocha and promises
Chai-as-Promised
Test doubles with promises
Organizing our test code
The storage object pattern
The example factory pattern
Finishing the scenario
Parameterized scenarios
Finishing our feature
Summary
4. Cucumber.js and Gherkin
Getting started with Gherkin and Cucumber.js
Preparing your project
Writing your first scenario in Gherkin
Executing Gherkin
The World object pattern
Better step handlers
Better reporting
Writing advanced scenarios
Gherkin example tables
Consolidating steps
Advanced setup
Gherkin-driven example factory
Implicit versus explicit setup
The Background section
Parameterized scenarios
Finishing the feature
Useful Cucumber.js features
Tagging features and scenarios
Hooks
The before hook
The after hook
The around hook
Non-English Gherkin
Cucumber.js or Mocha?
Summary
5. Testing a REST Web API
The approach
A strategy to test web APIs
Mocha or Cucumber.js?
The plan
Testing the GET order feature
Exploring our feature a bit
Starting, stopping, and setting up our server
Testing whether the API responds with 200 Ok
Should we use a realistic order object?
Implementing the test
Testing our HAL resource for orders
The contract with the business layer
Finishing the scenario
Testing slave resources
The order actions
Testing embedded resources
Extracting cross-cutting scenarios
Homework!
Summary
6. Testing a UI Using WebDriverJS
Our strategy for UI testing
Choosing the right tests for the UI
The testing architecture
WebDriverJS
Finding and interacting with elements
Complex UI interaction
Injecting scripts
Command control flows
Taking screenshots
Working with several tabs and frames
Testing a rich Internet application
The setup
The test HTML page
Serving the HTML page and scripts
Using browserify to pack our code
Creating a WebDriver session
Testing whether our view updates the HTML
Testing whether our view reacts with the user
What about our UI control logic?
Summary
7. The Page Object Pattern
Introducing the Page Object pattern
Best practices for page objects
A page object for a rich UI
Building a page object that reads the DOM
Building a page object that interacts with the DOM
Testing the navigation
Summary
8. Testing in Several Browsers with Protractor and WebDriver
Testing in several browsers with WebDriver
Testing with PhantomJS
Running in several browsers
The Selenium Server
Welcome Protractor!
Running the tests in parallel
Other useful configuration options
Using the Protractor API
Summary
9. Testing Against External Systems
Writing good test doubles
Testing against external systems
Testing against a database
Accessing the DB directly
Treating the DAO as a collection
Testing against a third-party system
The record-and-replay testing pattern
Summary
10. Final Thoughts
TDD versus BDD
A roadmap to BDD
BDD versus integration testing
BDD is for testing problem domains
Concluding the book
Next steps?
Summary
Index

Learning Behavior-driven Development with JavaScript

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: February 2015
Production reference: 1130215
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-264-2
www.packtpub.com

Credits

Author
Enrique Amodeo
Reviewers
Domenico Luciani
Mihir Mone
Takeharu Oshida
Juri Strumpflohner
Commissioning Editor
Pramila Balan
Acquisition Editor
Richard Brookes-Bland
Content Development Editors
Sriram Neelakantan
Sharvari Tawde
Technical Editor
Indrajit A. Das
Copy Editors
Karuna Narayanan
Laxmi Subramanian
Project Coordinator
Judie Jose
Proofreaders
Stephen Copestake
Maria Gould
Paul Hindle
Indexer
Priya Sane
Graphics
Sheetal Aute
Production Coordinator
Nitesh Thakur
Cover Work
Nitesh Thakur

About the Author

Enrique Amodeo is an experienced software engineer currently working and living in Berlin. He is a very eclectic professional with very different interests and more than 15 years of experience. Some of his areas of expertise are JS, BDD/TDD, REST, NoSQL, object-oriented programming, and functional programming.
As an agile practitioner, he uses BDD and emergent design in his everyday work and tries to travel light. Experienced in both frontend and server-side development, he has worked with several technical stacks, including Java/JEE, but since 2005, he prefers to focus on JS and HTML5. He is now very happy to be able to apply his JS knowledge to the server-side development, thanks to projects such as Node.js.
He also has written a book in Spanish on designing web APIs, following the REST and hypermedia approach (https://leanpub.com/introduccion_apis_rest).

About the Reviewers

Domenico Luciani is a software and web developer and compulsive coder. He is curious and is addicted to coffee. He is a computer science student and a passionate pentester and computer-vision fanatic.
Having fallen in love with his job, he lives in Italy; currently, he is working for many companies in his country as a software/web developer. You can find more information on him at http://dlion.it/.
Mihir Mone is a postgraduate from Monash University, Australia. Although he did his post graduation in network computing, these days, he mainly does ...

Table of contents