Testing JavaScript Applications
Lucas da Costa
  • MEAP began May 2020
  • Publication in Spring 2021 (estimated)
  • ISBN 9781617297915
  • 525 pages (estimated)
  • printed in black & white

I was pleasantly surprised that a book about testing would be this much fun to read!

Rodney Weis
Automated testing will help you write high-quality software in less time, with more confidence, fewer bugs, and without constant manual oversight. Testing JavaScript Applications is a guide to building a comprehensive and reliable JS application testing suite, covering both how to write tests and how JS testing tools work under the hood. You’ll learn from Lucas de Costa, a core contributor to popular JS testing libraries, as he shares a quality mindset for making testing decisions that deliver a real contribution to your business. You’ll benefit from informative explanations and diagrams, easily-transferable code samples, and useful tips on using the latest and most consolidated libraries and frameworks of the JavaScript ecosystem.

About the Technology

No developer wants to waste time making sure every application feature still works whenever they push new code to production. Thankfully, automated testing delivers quick and precise feedback on whether your application still functions correctly every time you update it. With automated testing, you can validate your application with a single command—and unlike humans, machines don’t forget steps or make mistakes!

About the book

Testing JavaScript Applications is a guide to creating JavaScript tests that are targeted to your application’s specific needs. Dripping with the insight author Lucas da Costa has developed as a core contributor to some of the most popular JS testing libraries, this book offers dozens of detailed code samples that you can apply to your own projects. You’ll learn how to write tests for both backend and frontend applications, covering the full spectrum of testing types so you can pick an approach that’s right for you. Taking on the role of a developer for a bakery’s web store, you’ll learn to validate different aspects including databases, third-party services, and how to spin-up a real browser instance to interact with the entire application. All examples are delivered using the popular testing tool Jest and modern packages of the JavaScript ecosystem.
Table of Contents detailed table of contents

Part 1: Tests matter

1 An introduction to automated testing

1.1 What is an automated test?

1.2 Why automated tests matter

1.2.1 Predictability

1.2.2 Reproducibility

1.2.3 Collaboration

1.2.4 Speed

1.3 Summary

2 What to test and when

2.1 The testing pyramid

2.2 Unit tests

2.3 Integration tests

2.4 End-to-end tests

2.4.1 Testing HTTP APIs

2.4.2 Testing GUIs

2.4.3 Acceptance tests and End-to-end tests are not the same

2.5 Exploratory testing and the value of QA

2.6 Tests, cost, and revenue

2.7 Summary

Part 2: Writting tests

3 Testing techniques

3.1 Organising test suites

3.1.1 Breaking down tests

3.1.2 Parallelism

3.1.3 Global Hooks

3.1.4 Atomicity

3.2 Writing good assertions

3.2.1 Assertion counting

3.2.2 Loose assertions

3.2.3 Using custom matchers

3.2.4 Circular assertions

3.3 Test doubles: mocks, stubs and spies

3.3.1 Mocking imports

3.4 Choosing what to test

3.4.1 Don’t test third-party software

3.4.2 To mock, or not to mock, that’s the question

3.4.3 When in doubt, choose integration tests

3.5 Summary

3.5.1 Organising test suites

3.5.2 Writing good assertions

3.5.3 Test doubles: mocks, stubs, and spies

3.5.4 Choosing what to test

4 Testing back-end applications

4.1 Structuring a testing environment

4.1.1 End-to-end testing

4.1.2 Integration testing

4.1.3 Unit testing

4.2 Testing HTTP endpoints

4.2.1 Testing middlewares

4.3 Dealing with external dependencies

4.3.1 Integrations with databases

4.3.2 Integrations with other APIs

4.4 Eliminating non-determinism

4.4.1 Parallelism and shared resources

4.4.2 Dealing with time

4.5 Reducing costs while preserving quality

4.5.1 Reducing overlap between tests

4.5.2 Creating transitive guarantees

4.5.3 Turning assertions into pre-conditions

4.6 Summary

5 Testing front-end applications

5.1 Introducing JSDOM

5.2 Asserting on the DOM

5.2.1 Making it easier to find elements

5.2.2 Writing better assertions

5.3 Handling events

5.4 Testing and browser APIs

5.4.1 Testing a localStorage integration

5.4.2 Testing a History API integration

5.5 Dealing with sockets and HTTP requests

5.5.1 Tests involving HTTP requests

5.5.2 Tests involving web-sockets

5.6 Summary

6 Testing React components

6.1 Setting up a test environment for React

6.1.1 Setting up a React application

6.1.2 Setting up a testing environment

6.2 An overview of React testing libraries

6.2.1 Rendering components and the DOM

6.2.2 React Testing Library

6.2.3 Enzyme

6.2.4 React Test Renderer

6.3 Testing component interaction

6.3.1 Stubbing components

6.4 Snapshot testing

6.4.1 Snapshots beyond components

6.4.2 Serializers

6.5 Testing styles

6.6 Component-level acceptance tests and component stories

6.6.1 Writing stories

6.6.2 Writing documentation

6.7 Summary

7 Test-driven development

7.1 The philosophy behind test-driven development

7.1.1 What test-driven development is

7.1.2 Adjusting the size your iterations

7.1.3 Why adopt test-driven development

7.1.4 When not to apply test-driven development

7.2 Writing a JavaScript module using TDD

7.3 Setting up a proper environment for TDD to succeed

7.3.1 What bottom-up and top-down testing mean

7.3.2 How top-down and bottom-up approaches impact a test-driven workflow

7.3.3 The pros and cons of bottom-up versus top-down approaches

7.4 Balancing maintenance costs, delivery speed and brittleness

7.4.1 Test-driven implementation

7.4.2 Test-driven maintenance

7.5 Setting up an environment for TDD to succeed

7.5.1 Team-wide adoption

7.5.2 Keeping distinct lanes

7.5.3 Pairing

7.5.4 Supplementary testing

7.6 TDD, BDD, validations and specifications

7.7 Summary

8 End-to-end Testing

Part 3: Business Impact

9 Continuous Integration & Continuous Delivery

10 A culture of quality


Setting up a development environment

Asynchronicity and tests

What's inside

  • Writing practical tests that make a real business contribution
  • Writing tests for both front-end and back-end applications
  • Managing the costs and complexity of your tests
  • Practicing test-driven development
  • Dealing with external dependencies, like databases or third-party APIs
  • Supporting tests by creating a "culture of quality"

About the reader

For junior JavaScript developers. No testing experience required.

About the author

Lucas da Costa is a core maintainer of Chai and Sinon.JS, two of the most popular testing tools in the JavaScript ecosystem. He has also contributed to Jest and other relevant open-source projects. Lucas is committed to a culture of sharing and has spoken at major software engineering conferences, including JSConf Colombia, FluentConf, HolyJS, CityJSConf London, and many others.

placing your order...

Don't refresh or navigate away from the page.
Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
print book $59.99 pBook + eBook + liveBook
Additional shipping charges may apply
Testing JavaScript Applications (print book) added to cart
continue shopping
go to cart

eBook $47.99 3 formats + liveBook
Testing JavaScript Applications (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.

FREE domestic shipping on three or more pBooks