Svelte with test-driven development advance your skills and write effective automated tests with Vitest, Playwright, and Cucumber.js

Build robust and performant applications by developing SvelteKit applications using automated testing and TDD techniques, including unit and end-to-end testing, custom matchers, component mocking, and authentication Purchase of the print or Kindle book includes a free PDF eBook Key Features Understa...

Descripción completa

Detalles Bibliográficos
Otros Autores: Irvine, Daniel, author (author)
Formato: Libro electrónico
Idioma:Inglés
Publicado: Birmingham, England : Packt Publishing Ltd [2023]
Edición:1st ed
Materias:
Ver en Biblioteca Universitat Ramon Llull:https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009755148206719
Tabla de Contenidos:
  • Cover
  • Title Page
  • Copyright and Credits
  • Contributors
  • Table of Contents
  • Preface
  • Part 1: Learning the TDD Cycle
  • Chapter 1: Setting up for Testing
  • Technical requirements
  • Creating a new SvelteKit project
  • Installing and running Playwright
  • Running Vitest
  • Preparing your development environment for frequent unit testing
  • Choosing your editor
  • Creating a shell alias
  • Changing the test runner to report each test name
  • Watching the test fail
  • Configuring support for Svelte component tests
  • Installing jsdom and testing library helpers
  • Writing a test for the DOM
  • Writing a first Svelte component test
  • Ensuring the DOM is cleared after each test run
  • Restoring mocks automatically
  • Optional configuration
  • Configuring Prettier's print width
  • Reducing the tab width in the Terminal
  • Summary
  • Chapter 2: Introducing the Red-Green-Refactor Workflow
  • Technical requirements
  • Understanding the Red-Green-Refactor workflow
  • Thinking ahead with some up-front design
  • The Birthdays application
  • Writing a failing test
  • Making it pass
  • Repeating the process
  • Refactoring the tests
  • Cleaning up warnings
  • Adding a third test to triangulate
  • Adding styles to the component
  • Summary
  • Chapter 3: Loading Data into a Route
  • Technical requirements
  • Using Playwright to specify end-to-end behavior
  • Writing the test and watching it fail
  • Understanding the difference between Vitest tests and Playwright tests
  • Deciding an approach to make the end-to-end test pass
  • Test-driving the load function
  • Test-driving the page component
  • Summary
  • Chapter 4: Saving Form Data
  • Technical requirements
  • Adding a Playwright test for data input
  • Test-driving a SvelteKit form
  • Adding the form component to the page component
  • Test-driving a SvelteKit form action.
  • Building a factory for the FormData objects
  • Building a Vitest test suite for the form action
  • Summary
  • Chapter 5: Validating Form Data
  • Technical requirements
  • Adding a Playwright test for validating form errors
  • Displaying SvelteKit form errors
  • Passing the form data through the page component
  • Validating data in the form action
  • Clearing the data store between tests
  • Summary
  • Chapter 6: Editing Form Data
  • Technical requirements
  • Planning the path ahead
  • Adding a Playwright test for editing form data
  • Evolving the repository to allow ID lookup
  • Updating the form action to handle edits
  • Replacing items in the repository
  • Protecting against unknown identifiers
  • Updating return values to include identifiers
  • Updating the list page with a new edit mode
  • Adding a toggle mode to the page
  • Summary
  • Part 2: Refactoring Tests and Application Code
  • Chapter 7: Tidying up Test Suites
  • Technical requirements
  • Using page object models in Playwright tests
  • Extracting an action helper
  • Extracting a factory method for creating data objects
  • Summary
  • Chapter 8: Creating Matchers to Simplify Tests
  • Technical requirements
  • Test-driving the pass or failure of an expectation
  • Understanding matcher structure
  • Testing a matcher
  • Writing the toBeUnprocessableEntity matcher
  • Providing extra information in failure messages
  • Implementing the negated matcher
  • Updating existing tests to use the matcher
  • Summary
  • Chapter 9: Extracting Logic Out of the Framework
  • Technical requirements
  • Migrating tests with a test todo list
  • Porting tests from the form action
  • Duplicating form validation behavior in the repository
  • Extracting common methods
  • Summary
  • Chapter 10: Test-Driving API Endpoints
  • Technical requirements
  • Creating a service test with Playwright.
  • Adding an API endpoint for retrieving data
  • Adding an API endpoint for saving data
  • Adding an API endpoint for updating data
  • Summary
  • Chapter 11: Replacing Behavior with a Side-By-Side Implementation
  • Technical requirements
  • Updating the route loader to use the API
  • Updating the page form action to use the API
  • Using a server hook to seed sample data
  • Summary
  • Chapter 12: Using Component Mocks to Clarify Tests
  • Technical requirements
  • Avoiding component mocks
  • Avoiding overtesting using TDD
  • Using hand-rolled component stubs
  • Rendering all props within a component stub
  • Checking the ordering of component instances
  • Dealing with complex props
  • Dispatching component events
  • Using a component mock library
  • Installing the library
  • Writing tests using the componentDouble function
  • Summary
  • Chapter 13: Adding Cucumber Tests
  • Technical requirements
  • Creating the feature file
  • Setting up a Playwright world object
  • Implementing the step definitions
  • Summary
  • Part 3: Testing SvelteKit Features
  • Chapter 14: Testing Authentication
  • Technical requirements
  • Testing authentication with Playwright
  • Creating an auth profile for dev and test modes
  • Writing tests for login
  • Updating existing tests to authenticate the user
  • Testing authentication with Vitest
  • Defining a session factory
  • Updating existing tests for page load functions
  • Updating existing tests for form actions
  • Summary
  • Chapter 15: Test-Driving Svelte Stores
  • Technical requirements
  • Designing a store for birthdays
  • Writing tests for reading store values
  • Writing tests for updating store values
  • Summary
  • Chapter 16: Test-Driving Service Workers
  • Technical requirements
  • Adding a Playwright test for offline access
  • Implementing the service worker
  • Summary
  • Index
  • Other Books You May Enjoy.