React Testing Library Tutorial #10 - Fire Events

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ต.ค. 2024
  • Check out Laith's TH-cam channel for more tutorials:
    / @laithacademy
    🐱‍💻 Access the course files on GitHub:
    github.com/har...
    🐱‍👤 Get access to extra premium courses on Net Ninja Pro:
    netninja.dev
    🐱‍💻 Full React Course:
    • Full React Tutorial #1...
    🐱‍💻 Social Links:
    Facebook - / thenetninjauk
    Twitter - / thenetninjauk
    Instagram - / thenetninja

ความคิดเห็น • 37

  • @ClutchProd
    @ClutchProd 2 ปีที่แล้ว +10

    Might be good to also mention the userEvent library to simulate key presses and clicks, so you can type the value into the input box.

    • @suhasrao4324
      @suhasrao4324 ปีที่แล้ว +2

      Official docs suggests using userEvent over fireEvent. Below is for userEvent v14+
      import userEvent from "@testing-library/user-event";
      const mockSetTodo = jest.fn();
      describe("User Input Component", () => {
      test("should be able to type into input field", async () => {
      render();
      const inputElement = screen.getByPlaceholderText(/Add a new task here.../i);
      await userEvent.setup().type(inputElement, "Shipping World!");
      expect(inputElement.value).toBe("Shipping World!");
      });

      test("renders an empty input field when 'add' button is clicked", async () => {
      render();
      const inputElement = screen.getByPlaceholderText(/Add a new task here.../i);
      const buttonElement = screen.getByRole('button', { name: /Add/i});
      const user = userEvent.setup();
      await user.type(inputElement, "Shipping World!");
      await user.click(buttonElement);
      expect(inputElement.value).toBe("");
      });
      });

  • @michaelsaucedo3952
    @michaelsaucedo3952 2 ปีที่แล้ว +1

    Liking this. I've been wanting to add testing to my React abilities. 🃏

  • @exodion4173
    @exodion4173 3 ปีที่แล้ว +7

    Amazing explanation.

  • @romimaximus
    @romimaximus 3 ปีที่แล้ว +4

    At 7:12, i didnt get where that "jest" came from ? if you can, please explain, im a little confused, is that another testing library ? if so , do i have to install it to use it ? i apreciate for this great testing tutorial playlist, its really helping me a lot !! 👍

    • @neenus
      @neenus 3 ปีที่แล้ว +6

      jest is already installed as part of testing-library in a react app that is created with create-react-app... if you look at your package.json file you should see @testing-library/jest-dom listed under dependencies

    • @romimaximus
      @romimaximus 3 ปีที่แล้ว +2

      @@neenus ok, i didnt know that, i thought that i have to install it, but thank you for your feedback 😎👍

  • @mun6048
    @mun6048 2 ปีที่แล้ว

    Async is not required while getting element from a component(5:12) ?

  • @thesimplypleasure4746
    @thesimplypleasure4746 3 ปีที่แล้ว +4

    It's gonna be awesome sir 👍😍

    • @80Vikram
      @80Vikram 3 ปีที่แล้ว +1

      Chole bhature ka re ??

  • @swagboysahil530
    @swagboysahil530 3 ปีที่แล้ว +2

    hey, I got this error at 11:00 "messageParent" can only be used inside a worker
    could not find much useful info about this error.how to resolve it ?

    • @rossidude
      @rossidude 2 ปีที่แล้ว +2

      Remember to use the .value property of your inputElement

  • @80Vikram
    @80Vikram 3 ปีที่แล้ว +5

    Thanks a ton, god bless you

  • @tribaldeni
    @tribaldeni ปีที่แล้ว +1

    what if you're using context to pass values

  • @sagarreddy7461
    @sagarreddy7461 3 ปีที่แล้ว +1

    thanks laith n shaun.

  • @vikasni95
    @vikasni95 2 ปีที่แล้ว +1

    This is just a masterpiece 😊

    • @NetNinja
      @NetNinja  2 ปีที่แล้ว +2

      Thank you!

  • @sardorjumanazarov441
    @sardorjumanazarov441 3 ปีที่แล้ว +2

    wow superb, keep goin

  • @franklinrodriguez5427
    @franklinrodriguez5427 2 ปีที่แล้ว +3

    why u use async?

  • @cbn4000
    @cbn4000 2 ปีที่แล้ว

    I'm getting "undefined is not iterable" when running the last test.

  • @albeque
    @albeque 2 ปีที่แล้ว

    Does anyone know how to test hover on button? I tried so many ways

  • @doniaelfouly4142
    @doniaelfouly4142 9 หลายเดือนก่อน

    thanks

  • @EddieCheng174
    @EddieCheng174 3 ปีที่แล้ว

    7:36 Interestingly, instead of "Add a new task here...", I accidentally tried "Add a new task here" and it still passed the test.

    • @camdoes739
      @camdoes739 3 ปีที่แล้ว +1

      same, i tried it with 'A' as well and it passed. it seems that getByPlaceholderText does not perform exact search, or actually, it might be something with regular expressions

    • @camdoes739
      @camdoes739 3 ปีที่แล้ว +1

      confirmed hahaha it is something with regular expressions. if you use a string, it does throw an error

    • @EddieCheng174
      @EddieCheng174 3 ปีที่แล้ว

      @@camdoes739 cool thx!

    • @EddieCheng174
      @EddieCheng174 2 ปีที่แล้ว

      @Loukas Piloidis thanks for clear explanation

  • @batuhankir8402
    @batuhankir8402 2 ปีที่แล้ว

    gg

  • @akaraze749
    @akaraze749 2 ปีที่แล้ว

    It'll be better if you speak less BS and be more on point.