Book Image

Learning Behavior-driven development with Javascript

Book Image

Learning Behavior-driven development with Javascript

Overview of this book

Table of Contents (17 chapters)
Learning Behavior-driven Development with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Test doubles with Sinon


A few weeks after going to production, our validator is a complete success but it also happens that potential new customers would like to have different sets of validation rules. Fortunately, our validator is configurable, but we somehow need to specify a different configuration for each customer.

The act of configuring a different set of rules for each customer is clearly another operation of the system and, hence, a different feature, so we are not really interested in testing it in the validator tests. We would like to isolate the tests about the validator feature and the configuration feature. To do so, we need to create an interface in a way that allows the validator to ask for the correct set of rules for the configuration. Then we can create a test double for such an interface in our tests. The test double will impersonate the real configuration and allow us to isolate our tests.

When creating these test doubles we need to design the shape of the interfaces and...