O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Vue.js Applications

Book Description

With Testing Vue.js Applications, you’ll discover effective testing methods for Vue applications. You’ll enjoy author Edd Yerburgh’s engaging style and fun real-world examples as you learn to use the Jest framework to run tests for a Hacker News application built with Vue, Vuex, and Vue Router. This comprehensive guide teaches the best testing practices in Vue along with an evergreen methodology that applies to any web dev process.

Table of Contents

  1. Copyright
  2. Brief Table of Contents
  3. Table of Contents
  4. The frontend testing pyramid
  5. Preface
  6. Acknowledgments
  7. About this book
    1. Who should read this book
    2. How this book is organized
    3. About the code
    4. Online resources
    5. Book forum
  8. About the author
  9. About the cover illustration
  10. Chapter 1. Introduction to testing Vue applications
    1. 1.1. Defining testing
    2. 1.2. Testing overview
    3. 1.3. Writing a Hacker News application
    4. 1.4. Vue testing overview
    5. Summary
  11. Chapter 2. Creating your first test
    1. 2.1. Understanding a Vue project structure
    2. 2.2. Introduction to Jest
    3. 2.3. Introduction to Vue Test Utils
    4. 2.4. Debugging tests with Chrome Debugger
    5. Summary
    6. Exercises
  12. Chapter 3. Testing rendered component output
    1. 3.1. Creating test specifications
    2. 3.2. Testing rendered text
    3. 3.3. Testing DOM attributes
    4. 3.4. Testing how many components are rendered
    5. 3.5. Testing props
    6. 3.6. Testing classes
    7. 3.7. Testing style
    8. 3.8. When to test rendered component output
    9. Summary
    10. Exercises
  13. Chapter 4. Testing component methods
    1. 4.1. Testing public and private component methods
    2. 4.2. Testing timer functions
    3. 4.3. Adding properties to the Vue instance
    4. 4.4. Mocking code
    5. 4.5. Mocking module dependencies
    6. Summary
    7. Exercises
  14. Chapter 5. Testing events
    1. 5.1. Testing native DOM events
    2. 5.2. Testing custom Vue events
    3. 5.3. Testing input forms
    4. 5.4. Understanding the limitations of jsdom
    5. Summary
    6. Exercises
  15. Chapter 6. Understanding Vuex
    1. 6.1. Understanding state
    2. 6.2. The problem Vuex solves
    3. 6.3. Understanding the Vuex store
    4. Summary
  16. Chapter 7. Testing Vuex
    1. 7.1. Understanding the store design
    2. 7.2. Adding Vuex to the project
    3. 7.3. Testing Vuex store parts separately
    4. 7.4. Testing a Vuex store instance
    5. 7.5. Testing Vuex in components
    6. Summary
    7. Exercises
  17. Chapter 8. Organizing tests with factory functions
    1. 8.1. Understanding factory functions
    2. 8.2. Creating a store factory function
    3. 8.3. Overwriting default options in factory functions
    4. 8.4. Creating a wrapper factory function
    5. Summary
    6. Exercises
  18. Chapter 9. Understanding Vue Router
    1. 9.1. Understanding routing
    2. Summary
  19. Chapter 10. Testing Vue Router
    1. 10.1. Testing router properties
    2. 10.2. Testing the RouterLink component
    3. 10.3. Using Vuex with Vue Router
    4. Summary
    5. Exercises
  20. Chapter 11. Testing mixins and filters
    1. 11.1. Testing mixins
    2. 11.2. Testing filters
    3. Summary
    4. Exercises
  21. Chapter 12. Writing snapshot tests
    1. 12.1. Understanding snapshot tests
    2. 12.2. Adding snapshot tests to your workflow
    3. Summary
    4. Exercises
  22. Chapter 13. Testing server-side rendering
    1. 13.1. Understanding server-side rendering
    2. 13.2. Testing server-side rendered components
    3. 13.3. Testing status codes with SuperTest
    4. 13.4. Testing SSR implicitly
    5. Summary
    6. Exercises
  23. Chapter 14. Writing end-to-end tests
    1. 14.1. Understanding end-to-end tests
    2. 14.2. Adding Nightwatch to a project
    3. 14.3. Writing end-to-end tests with Nightwatch
    4. 14.4. Running end-to-end tests in multiple browsers
    5. Summary
    6. Where to go from here
  24. Appendix A. Setting up your environment
    1. A.1 Choosing a text editor
    2. A.2 Using the command line
    3. A.3 Installing Chrome
    4. A.4 Installing the Vue.js devtools Chrome extension
    5. A.5 Installing Node and npm
    6. A.6 Installing Git
    7. A.7 Starting a new chapter
    8. A.8 Starting chapter 5
    9. A.9 Installing the Java Development Kit
  25. Appendix B. Running the production build
    1. B.1 Understanding the production build
    2. B.2 Running the Hacker News production build locally
  26. Appendix C. Exercise answers
    1. Chapter 2
    2. Chapter 3
    3. Chapter 4
    4. Chapter 5
    5. Chapter 7
    6. Chapter 8
    7. Chapter 10
    8. Chapter 11
    9. Chapter 12
    10. Chapter 13
  27. Index
  28. List of Figures
  29. List of Tables
  30. List of Listings