2 options
Svelte with test-driven development : advance your skills and write effective automated tests with Vitest, Playwright, and Cucumber.js / Daniel Irvine.
- Format:
- Book
- Author/Creator:
- Irvine, Daniel, author.
- Language:
- English
- Subjects (All):
- Computer software--Testing.
- Computer software.
- Automatic test equipment.
- Application software--Testing.
- Application software.
- Application software--Testing--Automation.
- Physical Description:
- 1 online resource (250 pages)
- Edition:
- 1st ed.
- Place of Publication:
- Birmingham, England : Packt Publishing Ltd., [2023]
- Summary:
- 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 Understand and master the test-driven development (TDD) workflow Explore the principles of unit testing with Vitest and end-to-end testing using Playwright and Cucumber.js Leverage practical examples of unit tests covering a range of SvelteKit framework features Book Description 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. What you will learn Create clear and concise Vitest unit tests helping the implementation of Svelte components Use Playwright and Cucumber.js to develop end-to-end tests that simulate user interactions and test the functionality of your application Leverage component mocks to isolate and test individual components Write unit tests for a range of Svelte framework features Explore effective refactoring techniques to keep your Svelte application code and test suites clean Build high-quality Svelte applications that are well-tested, performant, and resilient to changes Who this book is for This book is an essential guide for Svelte developers seeking to enhance their development process by learning the TDD workflow and its application. Whether you are an experienced developer or new to automated testing, this book helps you gain a practical approach to improving your workflow. The examples are written in JavaScript, making them accessible to all developers, including TypeScript developers.
- Contents:
- 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
- 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
- Chapter 3: Loading Data into a Route
- 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
- Chapter 4: Saving Form Data
- 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
- Chapter 5: Validating Form Data
- 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
- Chapter 6: Editing Form Data
- 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
- Part 2: Refactoring Tests and Application Code
- Chapter 7: Tidying up Test Suites
- Using page object models in Playwright tests
- Extracting an action helper
- Extracting a factory method for creating data objects
- Chapter 8: Creating Matchers to Simplify Tests
- 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
- Chapter 9: Extracting Logic Out of the Framework
- Migrating tests with a test todo list
- Porting tests from the form action
- Duplicating form validation behavior in the repository
- Extracting common methods
- Chapter 10: Test-Driving API Endpoints
- 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
- Chapter 11: Replacing Behavior with a Side-By-Side Implementation
- 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
- Chapter 12: Using Component Mocks to Clarify Tests
- 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
- Chapter 13: Adding Cucumber Tests
- Creating the feature file
- Setting up a Playwright world object
- Implementing the step definitions
- Part 3: Testing SvelteKit Features
- Chapter 14: Testing Authentication
- 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
- Chapter 15: Test-Driving Svelte Stores
- Designing a store for birthdays
- Writing tests for reading store values
- Writing tests for updating store values
- Chapter 16: Test-Driving Service Workers
- Adding a Playwright test for offline access
- Implementing the service worker
- Index
- Other Books You May Enjoy.
- Notes:
- Includes index.
- Description based on print version record.
- ISBN:
- 9781837630950
- 183763095X
- OCLC:
- 1388633679
The Penn Libraries is committed to describing library materials using current, accurate, and responsible language. If you discover outdated or inaccurate language, please fill out this feedback form to report it and suggest alternative language.