
Svelte with Test-Driven Development
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Svelte is a popular front-end framework used for its focus on performance and user-friendliness, and test-driven development (TDD) is a powerful approach that helps in creating automated tests before writing code. By combining them, you can create efficient, maintainable code for modern applications. Svelte with Test-Driven Development will help you learn effective automated testing practices to build and maintain Svelte applications.
In the first part of the book, you'll find a guided walkthrough on building a SvelteKit application using the TDD workflow. You'll uncover the main concepts for writing effective unit test cases and practical advice for developing solid, maintainable test suites that can speed up application development while remaining effective as the application evolves. In the next part of the book, you'll focus on refactoring and advanced test techniques, such as using component mocks and writing BDD-style tests with the Cucumber.js framework. In the final part of the book, you'll explore how to test complex application and framework features, including authentication, Svelte stores, and service workers.
By the end of this book, you'll be well-equipped to build test-driven Svelte applications by employing theoretical and practical knowledge.
All prices
More details
Other editions
Additional editions

Content
- 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
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.
File format: ePUB
Copy protection: without DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Use a reader that can handle the file format ePUB, such as Adobe Digital Editions or FBReader – both free (see eBook Help).
- Tablet/Smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePUB works well for novels and non-fiction books – i.e., 'flowing' text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook does not use copy protection or Digital Rights Management
For more information, see our eBook Help page.