mercredi 18 novembre 2020

How to I test a react component with Jest that maps over an array of objects to match an object value that sets a value to be rendered

Below is the component I need to test. Sorry, its seems simple, but I'm new to React and Javascript.

import React from 'react';

export default ({ comments }) => {
  const renderedComments = comments.map(comment => {
    let content;

    if (comment.status === 'approved') {
      content = comment.content;
    }

    if (comment.status === 'pending') {
      content = 'This comment is awaiting moderation';
    }

    if (comment.status === 'rejected') {
      content = 'This comment has been rejected';
    }

    return <li key={comment.id}>{content}</li>;
  });

  return <div><h4>Reviewer Comments</h4><ul>{renderedComments}</ul></div>;
};

Aucun commentaire:

Enregistrer un commentaire