omer-genc / unit-test-emoji-search-react

I write unit test for emoji search app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unit Test

import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { paste } from "@testing-library/user-event/dist/paste";
import ClipboardJS from "clipboard";
import React from "react";
import App from "./App";


it("Header should be rendered successfully", () => {
  render(<App />);
  const header = document.querySelector("header");
  expect(header).toBeDefined();

})

it("The emoji list should be rendered in a successfully", () => {
  render(<App />);
  const emojiRows = document.querySelectorAll(".component-emoji-result-row");
  const arr = [...emojiRows];

  expect(arr.length).toBe(20);
})


it("Filtering should work", () => {
  render(<App />);
  const input = document.querySelector("input");
  userEvent.type(input, "Smile")
  const emojiRows = document.querySelectorAll(".component-emoji-result-row");
  const arr = [...emojiRows];
  expect(arr.length).toBeLessThan(20);

})

it("emoji copying should work",()=>{
  render(<App />);
  const itemToBeClicked = document.querySelector(".component-emoji-results").firstChild;
  document.execCommand = jest.fn();
  userEvent.click(itemToBeClicked);
  expect(document.execCommand).toHaveBeenCalledWith("copy");
})

About

I write unit test for emoji search app

License:MIT License


Languages

Language:JavaScript 64.8%Language:CSS 22.6%Language:HTML 12.6%