售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Test-Driven JavaScript Development
Table of Contents
Test-Driven JavaScript Development
Credits
About the Authors
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. Overview of TDD
Complexity of web pages
Understanding test-driven development
The need for testing
Types of testing
The life cycle of TDD
TDD microcycle
Agile and TDD
Benefits of TDD and common myths
Benefits
Myths
Summary
2. Testing Concepts
Unit testing
Unit testing frameworks
YUI Tests
Following the process
Preparing the environment
Following the life cycle
Writing a test
Running the test and seeing if test fails
Writing a production code
Running all tests
Cleaning up the code
Repeat
Using the browser console
setUp() and tearDown()
Test suites
Actions and assertions
Actions
Assertions
Benefits and pitfalls
Benefits of unit testing
Pitfalls of unit testing
Summary
3. Testing Tools
JsUnit
Getting started
Writing tests
Running tests
QUnit
Getting started
Writing tests
Running tests
Karma with Jasmine
Getting started
Writing tests
Running tests
DalekJS
Getting started
Writing tests
Actions
Assertions
Running tests
Summary
4. Jasmine
Understanding behavior-driven development
Setting up Jasmine
describe and specs
Expectations
Matchers
Set up and tear down
Spies
Tracking spies using calls
Creating a custom spy
Jasmine clock
Creating a custom matcher
Creating a custom equality tester
Asynchronous calls
The Jasmine Ajax plugin
Nesting suites
Disabling suites and specs
Summary
5. JsTestDriver
JsTestDriver
Overview
Getting started
Writing tests
Assertions
Capturing the browser
Restructuring your project
The configuration file
Running tests using the command prompt
Setting up JsTestDriver with IDE
Running the tests
Running Jasmine specs
Code coverage
Summary
6. Feature Detection
Understanding feature detection
Available methods and libraries
has.js
Writing custom tests
Modernizr
Downloading and setting up Modernizr
How it works
Using Modernizr
Polyfills
Loading polyfills
Supported browsers
Browser detection
User agent sniffing
Object detection
Features testing with Modernizr
CSS features
HTML5 features
Miscellaneous features
Plugins for additional tests
Modernizr methods
Modernizr.prefixed()
Modernizr.prefixedCSS()
Modernizr.mq()
Modernizr.on()
Modernizr.atRule()
Modernizr.addTest()
Modernizr.testStyles()
Modernizr.testProp()
Modernizr.testAllProps()
Modernizr.hasEvent()
Modernizr._prefixes and Modernizr._domPrefixes
Undetectable features
Summary
7. Observer Design Pattern
Overview
When to use it
Advantages
Disadvantages
Different implementations of the observer
Event dispatcher/listener
Publish/subscribe
Push versus pull
Sample code
Understanding patterns in API
The notify method
Subscribe
Unsubscribe
Observer with topics
Observer pattern using jQuery.Callbacks
Implementing the observer pattern using TDD
Red step (code with error)
Green step (with running code)
Refactoring
Hot swapping components
Browser compatibility of the observer API
Summary
8. Testing with Server-Side JS
Setting up the environment
Installing Node.js
Setting up the application
Choosing a test runner
Mocha and Chai
Server-side unit testing
Implementing the web server
Helpdesk – sample application
Setting up the MongoDB database
The Mocha test
Summary
9. Best Practices
TDD best practices
Follow proper rules to define test cases
Make test case names more readable
Keep the same name for test files and source files
Keep the name descriptive
Applying proper processes
Making sure that tests are written before starting implementation
Modifying/writing new code only when the test is failing
Running all the tests when we modify anything in the existing code
Existing tests should pass before new tests are written
Cleaning up code once all test cases are passed
Follow right development practices
Simple code that can be easily understood
Writing assertions first
One assertion per test is enough
Keep your focus on findability
Reducing duplication
Tests should run fast
Using mocks
Using stubs
Using setUp and tearDown methods
Choosing the right tool
Feature detection tools
Server-side testing tools
Asynchronous testing
Running time of unit tests
Browser support
Other features
JsLint
Summary
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜