Component Testing with Enzyme
Learn how to Test simple React components with Enzyme using shallow rendering.
As mentioned earlier, our project for the rest of the course is building a carousel. A carousel is a widget that shows a series of images to the user one at a time. The user has the ability to move between adjacent images in the series. The carousel can also auto-advance, like a slideshow. By the end of the course, our carousel will look like this:
Since this is fairly complex, we’re going to implement it as a primary component called Carousel
with two secondary components:
CarouselSlide
, an image shown in the carouselCarouselButton
, a button that lets the user control the slides
Let’s start by writing some tests for the simplest component: CarouselButton
is just going to render a <button>
. Why componentize it at all? Because we’re going to add styling to that <button>
in the next chapter. We’ll make assertions about the component using a ...