1. 2
    Exploring the Sample App for the Redux Testing Course
    2m 18s

Exploring the Sample App for the Redux Testing Course

Jamund Ferguson
InstructorJamund Ferguson
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 2 years ago

All of the code for this application can be found in the redux-shopping-cart github repo, specifically in the testing branch. An explanation for how it was built can be found by completing the Modern Redux with RTK and TypeScript course on egghead.

To quickly summarize a few of the things you need to know to be successful:

  1. This app is built with Redux Toolkit which has a slightly different syntax than standard Redux, however the testing examples should all work seamlessly in any Redux application

  2. The app is built on top of vite instead of the more popular create react app. The benefit of vite is that it installs and builds extremely quickly. One of the downsides of vite is that it doesn't come with any out-of-the-box testing support. It also has its own esbuild-based compiler, which is not currently compatible with jest, so we have to configure JSX & TypeScript support for jest even though vite handles it already.

  3. Almost all of the key files for the project are found in the src/features folder. "Slice" files are a Redux Toolkit convention and they contain all the redux code for that part of the application.

  4. You can get the app started by typing npm run dev and opening your browser to http://localhost:3000/.

Jamund Ferguson: Head over to the sample repo for this course in GitHub and make sure to select the testing branch from the list of branches. From there, click the Code button and copy the URL to clone the repo. Then, in a terminal window, wherever you'd like to work, type git clone and paste in that URL.

If you, like me, have already downloaded this repo for one of my other Redux courses, you may have this code checked out. I recommend typing redux-testing to create a folder specifically for this course. Cd into that folder.

Now, make sure you check out the testing branch by typing git checkout testing. From here, type npm install. When that's done, you can type npm run dev to launch the application we'll be testing. We'll go ahead and open that up here.

You can see, I've got a store here with a Products page, where you can add various items to your cart, and then a Cart page, where you can change the quantity, remove items and, finally, check out. That's our shop.

Let's take a look at our code base. The main thing we want to look at here is our src folder. Inside the src folder, you have an App.tsx file, which contains the three main routes of our application -- the Home route, the Products route and the Cart route.

The components for our Cart and Products page live inside the features folder alongside all related components. Here's Products.tsx, which loads our Products page. Here's Cart.tsx, which loads our Cart page. You can see that, beside each of these, we have a slice file.

The slice file's where all of our Redux logic lives for that part of the app, and it's where a lot of our testing will be focused.

Here is our productsSlice, and here is our cartSlice. Both of our slices here rely on the Redux toolkit helper to set up the reducers, thunks and selectors, but the techniques we'll be using to test them work just fine even if you're creating these by hand.

The other thing to note about our application is that it's built with Vite. Vite is what provides a super fast app refresh and module compilation that you'll see as you begin working in the application. You'll also notice here that we're using TypeScript throughout the application instead of plain old JavaScript.

That being said, pretty much all the techniques we talked about will translate perfectly into JavaScript. If you haven't already watched the course about how we built this application, I'd recommend starting there. Either way, let's get to testing.

egghead
egghead
~ a minute ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today