TAILIEUCHUNG - Test Driven JavaScript Development- P2

Test Driven JavaScript Development- P2:This book is about programming JavaScript for the real world, using the techniques and workflow suggested by Test-Driven Development. It is about gaining confidence in your code through test coverage, and gaining the ability to fearlessly refactor and organically evolve your code base. It is about writing modular and testable code. It is about writing JavaScript that works in a wide variety of environments and that doesn’t get in your user’s way. | Preface xxi While working through some of JavaScript s finer points I ll use unit tests to show you how the language behaves and we ll take the opportunity to let tests drive us through the implementation of some helper utilities which we ll use throughout Part III. Part III Real-World Test-Driven Development in JavaScript In this part we ll tackle a series of small projects in varying environments. We ll see howto develop a small generalpurpose JavaScript API develop a DOM dependent widget abstract browser differences implement a server-side JavaScript application and more all using test-driven development. This part focuses on how test-driven development can help in building cleaner API s better modularized code and more robust software. Each project introduces new test-related concepts and shows them in practice by implementing a fully functional yet limited piece of code. Throughout this part we will among other things learn how to test code that depends on browser API s timers event handlers DOM manipulation and asynchronous server requests . Ajax . We will also get to practice techniques such as stubbing refactoring and using design patterns to solve problems in elegant ways. Throughout each chapter in this part ideas on how to extend the functionality developed are offered giving you the ability to practice by improving the code on your own. Extended solutions are available from the book s I ve taken great care throughout these projects to produce runnable code that actually does things. The end result of the five chapters in Part III is a fully functional instant messaging chat client and server written exclusively using test-driven development in nothing but JavaScript. Part IV Testing Patterns The final part of the book reviews some of the techniques used throughout Part III from a wider angle. Test doubles such as mocks and stubs are investigated in closer detail along with different forms of test verification. Finally we review some .