Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Svelte with Test-Driven Development
Svelte with Test-Driven Development

Svelte with Test-Driven Development: Advance your skills and write effective automated tests with Vitest, Playwright, and Cucumber.js

eBook
$24.99 $27.99
Paperback
$34.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Svelte with Test-Driven Development

Setting up for Testing

Back when you were a young schoolchild, you probably learned to write by using a pencil on paper. Now that you’re older, it’s likely you prefer pens. For learners, pencils have a distinct advantage over pens in that mistakes are easy to correct, and when you first start writing out letters and words, you will be making a lot of mistakes. Pencils are also safer for small children – no caps or messy ink to worry about.

But pencils remain a valid writing instrument, and you might still have a personal preference for pencils over pens. The pencil is a perfectly good tool for the job.

Test-Driven Development (TDD) is a tool that can serve you in a similar way. It’s a great way to learn and grow as a developer. Many experienced developers prefer it for their day-to-day work over any alternative.

In this chapter, you’ll configure a work environment that’s designed to help you get the most out of TDD techniques. Since TDD asks you to do a bunch of small repetitive tasks – writing tests, running tests, committing early and often, and switching between test code and application code – it’s important that each of those tasks can be done easily and quickly.

It follows that an important personal discipline to cultivate is that of objectively critiquing your development tools. For every tool that you use, ask yourself this: is this tool serving me well? Is it easy and quick to use?

This could be your Integrated Development Environment (IDE), your operating system, your source code repository, your note-taking program, your time management utilities, and so on. Anything and everything you use in your day job. Scrutinize your tools. Throw away whatever isn’t working for you.

This is a very personal thing and depends a lot on experience and individuality. And your preferences are likely to change over time, too.

I often reach for very plain, simple, keyboard-driven tools that work for me consistently, regardless of the programming language I’m working in, such as the text editor Vim. It doesn’t offer any knowledge about the JavaScript programming language or the Svelte framework, but it makes me extremely effective at editing text.

But if you care about learning JavaScript or program design, then you might prefer an IDE that gives you JavaScript auto-complete suggestions and helpful project assistance.

This chapter walks through the setup of a new SvelteKit project and highlights all the individual choices you’ll need to make, and the additional extras you’ll need in order to practice effective TDD.

It covers the following topics:

  • Creating a new SvelteKit project
  • Preparing your development environment for frequent test runs
  • Configuring support for Svelte component tests
  • Optional configuration you may want to try

By the end of the chapter, you’ll know how to create a new Svelte project that is ready for test-driven feature building.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • 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

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.

Who is this book 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.

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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 30, 2023
Length: 250 pages
Edition : 1st
Language : English
ISBN-13 : 9781837630950
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 30, 2023
Length: 250 pages
Edition : 1st
Language : English
ISBN-13 : 9781837630950
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 101.96 109.97 8.01 saved
SvelteKit Up and Running
$34.99
Svelte with Test-Driven Development
$34.99
Real-World Svelte
$31.98 $39.99
Total $ 101.96 109.97 8.01 saved Stars icon

Table of Contents

21 Chapters
Part 1: Learning the TDD Cycle Chevron down icon Chevron up icon
Chapter 1: Setting up for Testing Chevron down icon Chevron up icon
Chapter 2: Introducing the Red-Green-Refactor Workflow Chevron down icon Chevron up icon
Chapter 3: Loading Data into a Route Chevron down icon Chevron up icon
Chapter 4: Saving Form Data Chevron down icon Chevron up icon
Chapter 5: Validating Form Data Chevron down icon Chevron up icon
Chapter 6: Editing Form Data Chevron down icon Chevron up icon
Part 2: Refactoring Tests and Application Code Chevron down icon Chevron up icon
Chapter 7: Tidying up Test Suites Chevron down icon Chevron up icon
Chapter 8: Creating Matchers to Simplify Tests Chevron down icon Chevron up icon
Chapter 9: Extracting Logic Out of the Framework Chevron down icon Chevron up icon
Chapter 10: Test-Driving API Endpoints Chevron down icon Chevron up icon
Chapter 11: Replacing Behavior with a Side-By-Side Implementation Chevron down icon Chevron up icon
Chapter 12: Using Component Mocks to Clarify Tests Chevron down icon Chevron up icon
Chapter 13: Adding Cucumber Tests Chevron down icon Chevron up icon
Part 3: Testing SvelteKit Features Chevron down icon Chevron up icon
Chapter 14: Testing Authentication Chevron down icon Chevron up icon
Chapter 15: Test-Driving Svelte Stores Chevron down icon Chevron up icon
Chapter 16: Test-Driving Service Workers Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9
(10 Ratings)
5 star 90%
4 star 10%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Theodore Spielman Jun 30, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm a few chapters into this book and wanted to put up my initial impression. I find a lot of programming books very dense and a struggle to get through, but this isn't one of them. It's surprisingly easy to read and follow along. Daniel Irvine was able to balance being informative and comprehensive enough for those new to svelte and tdd while not being verbose and tiresome. Personally, I've never been a fan of tdd, but I'm actually looking forward to diving deeper into the workflow outlined in the book and making use of it in my own projects. I'll have to follow up once I finish the book but so far packt seems to have put out another winner.
Amazon Verified review Amazon
Cameron Tully-Smith Jul 05, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Love the simplicity of the examples and the focus on TDD/overview of it. Nice approach to formalizing Svelte usage.
Amazon Verified review Amazon
Sukhmeet S Khalar Jul 03, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm a quarter of the way through the book, and it does a very good job of explaining Test Driven Development (TDD). It goes over the core concepts and features of TDD.Using SvelteKit is just a plus in my eyes. You don't need to know Svelte to go through this book. The author does a good job of balancing technical and practical points.
Amazon Verified review Amazon
Tim Hildegard Jul 31, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I liked the book very much. There aren't that many resources on the topic of TDD for Svelte, and the book does a nice job of showing how to use Vitest and Playwright.The book mostly uses numbered lists to show how to build up the tests and code in Red-Pass-Refactor cycles. It starts off with simple tests, and then gradually increases the complexity.The tests are all based on reasonably realistic examples, which makes the easy to port to one's own projects. On the flipside, the book can become a little repetitive, since the testing is very thorough and all code is shown. But I preferred that over having incomplete examples.
Amazon Verified review Amazon
Dylan Hildenbrand Aug 11, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Having tests to ensure code is behaving as expected is a great practice that can sometimes be tricky to implement. This book clearly demonstrates not only how to get started but how to ensure consistent practices are followed, leading to more reliable code. There are lots of different resources out there that explain testing but in my opinion, this book should be considered the definitive guide to testing SvelteKit applications.The book starts by introducing some basic testing concepts and helping the reader setup the environment to code alongside. It's highly recommended to run the code along with the book, but if you'd prefer simply to peruse it, there is a very well organized GitHub repository provided with all code samples. After introducing some basic tests, the complexity is gradually increased while the book demonstrates various testing and code refactoring techniques and practical examples. By the end of the book, I felt comfortable with testing some more advanced functionality like authentication and service workers. I can't wait to begin implementing everything taught here. I fully expect to be referring to this book very frequently throughout the refactoring process of my own applications.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.