mardi 4 juin 2019

Testing a switch-statement using Jest & Enzyme

I'm using a switch-statement to conditionally render components and I've been spending quite some time attempting to test but I just have no idea how to go about it and havent found any helpful resources online for this. Thanks for taking a look!

 componentToRender = (currentPath) => {
    const { years, tours, songs, shows, venues } = this.props;

    switch (currentPath) {
      case "/Years":
        return years.map(year => <Years key={year.date} year={year} />);
      case "/Tours":
        return tours.map(tour => <Tours key={tour.id} tour={tour} />);
      case "/Songs":
        return songs.map(song => <Songs key={song.id} song={song} />);
      case "/Venues":
        return venues.map(venue => <Venues key={venue.id} venue={venue} />);
      case "/Shows":
        return shows.map(show => <Shows key={show.id} show={show} />);
      case "/SetList":
        return <SetLists />;
      case "/UserStats":
        return <UserStats />;
      default:
        return <HomePage />;
    }
  };

Aucun commentaire:

Enregistrer un commentaire