You are previewing JavaScript Unit Testing.
O'Reilly logo
JavaScript Unit Testing

Book Description

This book covers the most popular modern JavaScript Unit testing frameworks and gives you a crash course in how to use and automate them. Lots of examples and practical instructions make learning easy and enjoyable.

  • Learn and understand, using practical examples, synchronous and asynchronous JavaScript unit testing

  • Cover the most popular JavaScript Unit Testing Frameworks including Jasmine, YUITest, QUnit, and JsTestDriver

  • Automate and integrate your JavaScript Unit Testing for ease and efficiency

  • In Detail

    The largest challenge for many developers’ day to day life is ensuring the support of, and assuring the reach of, their product. With the ever increasing number of mainstream web browsers this is becoming a more difficult task for JavaScript coders.

    From the beginning, JavaScript Unit Testing will show you how to reduce the time you spend testing, and automate and ensure efficiency in guaranteeing your success.

    JavaScript Unit Testing will introduce and help you master the art of efficiently performing and automating JavaScript Unit tests for your web applications.

    Using the most popular JavaScript unit testing frameworks, you will develop, integrate, and automate all the tests you need to ensure the widest reach and success of your web application.

    Covering the most popular JavaScript Unit testing frameworks of today, JavaScript Unit Testing is your bible to ensuring the functionality and success of all of your JavaScript and Ajax Web Applications.

    Starting with Jasmine, you will also learn about, and use, YUITest, QUnit, and JsTestDriver, integrate them into your projects, and use them together to generate reports.

    Learn to automate these tools, make them work for you, and include the power of these tools in your projects from day one.

    Table of Contents

    1. JavaScript Unit Testing
      1. Table of Contents
      2. JavaScript Unit Testing
      3. Credits
      4. About the Author
      5. About the Reviewer
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Unit Testing JavaScript Applications
        1. What unit testing is
        2. Why we need unit testing
        3. What Test-Driven Development (TDD) is
        4. Complexities in testing JavaScript applications
        5. Weather forecasting application
          1. Exploring the application's HTML and JavaScript code
          2. Running the weather application
        6. Summary
      9. 2. Jasmine
        1. Configuration
        2. Writing your first Jasmine test
        3. The nested describe blocks
        4. Jasmine matchers
          1. The toBe matcher
          2. The toBeDefined and toBeUndefined matchers
          3. The toBeNull matcher
          4. The toBeTruthy and toBeFalsy matchers
          5. The toContain matcher
          6. The toBeLessThan and toBeGreaterThan matchers
          7. The toMatch matcher
          8. Developing custom Jasmine matchers
        5. Testing asynchronous (Ajax) JavaScript code
          1. The runs() function
          2. The waits() function
          3. The waitsFor() function
          4. The spyOn() function
        6. HTML fixtures
          1. Configuring the jasmine-jquery plugin
          2. The loadFixtures module
        7. Testing the weather application
          1. Testing the LoginClient object
          2. Testing the RegistrationClient object
          3. Testing the WeatherClient object
          4. Running the weather application tests
        8. Summary
      10. 3. YUI Test
        1. Writing your first YUI test
        2. Assertions
          1. The assert assertion
          2. The areEqual and areNotEqual assertions
          3. The areSame and areNotSame assertions
          4. The datatype assertions
          5. Special value assertions
          6. The fail assertion
        3. Testing asynchronous (Ajax) JavaScript code
          1. The wait and resume functions
        4. Testing the weather application
          1. Testing the LoginClient object
          2. Testing the RegistrationClient object
          3. Testing the WeatherClient object
          4. Running the weather application tests
          5. Generating test reports
        5. Automation and integration with build management tools
          1. Configuring YUI Test Selenium Driver
          2. Using YUI Test Selenium Driver in the weather application
          3. Integration with build management tools
        6. Summary
      11. 4. QUnit
        1. Configuration
        2. Writing your first QUnit test
        3. Assertions
          1. The ok assertion
          2. The equal and notEqual assertions
          3. The deepEqual and notDeepEqual assertions
          4. The expect assertion
          5. Developing custom QUnit assertions
        4. Testing asynchronous (Ajax) JavaScript code
          1. The stop and start APIs
        5. Testing the weather application
          1. Testing the LoginClient object
          2. Testing the RegistrationClient object
          3. Testing the WeatherClient object
          4. Running the weather application tests
        6. Summary
      12. 5. JsTestDriver
        1. Architecture
        2. Configuration
        3. Writing your first JSTD test
        4. Assertions
          1. The assert, assertTrue, and assertFalse([msg], expression) assertions
          2. The assertEquals and assertNotEquals([msg], expected, actual) assertions
          3. The assertSame and assertNotSame([msg], expected, actual) assertions
          4. The datatype assertions
          5. Special value assertions
          6. The fail([msg]) assertion
        5. Testing asynchronous (Ajax) JavaScript code
          1. AsyncTestCase, queue, and callbacks
        6. Testing the weather application
          1. Testing the LoginClient object
          2. Testing the RegistrationClient object
          3. Testing the WeatherClient object
          4. Configuring the proxy
          5. Running the weather application tests
          6. Generating test reports
        7. Integration with other JavaScript test frameworks
          1. Integrating JSTD with Jasmine
          2. Integrating JSTD with QUnit
        8. Integration with build management tools
        9. Integration with the IDEs
          1. Eclipse integration
        10. Summary
      13. Index