Whether you need a high performance web application, fullstack architecture advisory, or an engineer who ships with urgency and care.
Jump directly on my calendar to talk about goals, timeline, and fit.
Let's start by cloning our already made todo app. We will be testing the crud function and also checking for UI updates. Vitest is easy to get started with. Just follow along and you will begin testing your apps soon.
Add Vitest,jsdom and necessary testing libraries for UI testing to get started.
You can additionally add the following scripts to package .json
Before testing our application, we need to set up some files to get started. Start by creating a new file test-utils that will have all the utilities for our tests.
//tests/test-utils.tsx
//tests/setup.ts
We need now to update our Vite config to include test files.
// vite.config.ts
First, let's start by performing component testing. For this, we can create a test file to test our input component. We can test as many scenarios as we like. Here, we will test if the component is rendered properly and if the input can change values and update as we require. Initially, we will test to see if the component in rendered to the document.
//components/Input/Input.test.tsx
First, we render the component making use of @testing-library/react and we will check if the component is rendered. We can additionally check for props and values the input component should have as the props have been passed in. for this we can again make use of helper functions provided by @testing-library/react to get the component properties. Here, we test to see if the input component has the label of "Add Todo" and we also check for the input box having the name 'Add Todo'.
We can now test our input for value changes and updates.
Here, we render the input then we check if the input box is present in the document. If the input box check passes we can then type anything we want into the input box. We then check if the input has the same value as we typed.
Now we can test our addtodo functionality in the app. Continue by creating a new file AddTodo.test.tsx . We can begin by checking if the UI for the form is present in the document.
//src/AddTodo.test.tsx
Now we can test the functionality of the add todo form. Here, we again test by rendering the App component and then check for the title of the remaining todo in the document. Then we add a new todo to the input and click on the button for adding. We then finally check if the newly added todo is also present in the UI document.
We successfully tested different scenarios for the todo app. We also made it possible to pass all the tests. Implement similarly in your apps now.
Explore more articles on software architecture, frontend craftsmanship, and backend engineering.



