Mock vs Spy in Testing with Jest: Which is Better?

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • In this video, we explore the differences between mocks and spies in testing with Jest. We'll dive into the benefits and drawbacks of each approach, and help you determine which one is best for your specific use case. Whether you're a seasoned developer or just starting out with Jest testing, this video is a must-watch. Join us as we explore the world of Jest testing and help you become a better developer.
    Link to the Code example: github.com/mohokh67/jest-mock...
    Jest Mock: jestjs.io/docs/mock-functions
    Jest Spy: jestjs.io/docs/jest-object#je...
    Chapters:
    0:00 - intro
    2:58 - Write tests
    5:30 - Write mocks in jest
    11:27 - Write spy in jest
    20:58 Mock and Spy comparison
  • Věda a technologie

Komentáře • 21

  • @0xVantwoutMaarten
    @0xVantwoutMaarten Před 21 dnem

    This is aweome Mohoo, as clear as it gets.

  • @edwarddemesaify
    @edwarddemesaify Před rokem +1

    Excellent tutorial... Thank you!

  • @sandyrubybassi3462
    @sandyrubybassi3462 Před 4 měsíci

    Best explanation i’ve come across 👌🏼

  • @user-zc7os7on7k
    @user-zc7os7on7k Před měsícem

    thanks for your explanation and straight to point tutorials

  • @BarakAlmog
    @BarakAlmog Před 5 měsíci

    Appreciate your effort so much! Thanks.
    I agree the font is a bit of a challenge,... still like it tho :)
    Thanks again!

  • @Maverick2k
    @Maverick2k Před 6 měsíci

    Just wanted to give kudos for your videos. I'm a senior dev, finally dabbling in proper testing and I found this video really easy to understand. I was wondering though, what which point is it better to spy vs mock?

  • @RRCaddick
    @RRCaddick Před 3 měsíci

    This is awesome! Was pulling my hair out yesterday dealing with jests mock hoisting and trying to change mock resolved for only a specific test, and I'm sure this will help. Why would we favour one over the other?

  • @MauroHenrique-vb6or
    @MauroHenrique-vb6or Před měsícem

    Beautiful

  • @Romul3003
    @Romul3003 Před rokem +13

    Great tutorial, terrible editor fonts, my eyes are bleeding

    • @scally9341
      @scally9341 Před 11 měsíci

      ^

    • @dev.channel
      @dev.channel  Před 9 měsíci

      Thanks for the feedback. I will not use this font in future videos

  • @Mr_MicDaniel
    @Mr_MicDaniel Před 2 měsíci

    I really enjoyed the tutorial it was superb
    Can you do this for Vitest and Prisma ORM. Thank
    I will really appreciate it

  • @aryakhaleqi1600
    @aryakhaleqi1600 Před rokem +1

    Graet

  • @sueluceromartinezherrera1825

    thanks! it was pretty clear, I just have a question, in this case the user file export the functions and you can import easily, but what happen if in my file The functions is not exported ? how can I access to that fuction in my test, hope I could be clear, greeting from mexico.

    • @dev.channel
      @dev.channel  Před 10 měsíci

      If it’s not exported then it can’t be imported and not tested either

    • @justinmiller3349
      @justinmiller3349 Před 2 měsíci

      @@dev.channel To be more precise, "private" or "internal" functions are not tested *directly* but as a developer you want to be aware of this and you can design your tests to ensure all of your internal logic is behaving as intended indirectly by ensuring that the imported function returns what is expected given several different inputs that the internal logic deals with. Using the --coverage flag with Jest can help uncover untested internal code.

  • @malgorzatastefanowicz4077
    @malgorzatastefanowicz4077 Před 10 měsíci +4

    cant watch it because of the font :/

    • @dev.channel
      @dev.channel  Před 9 měsíci

      Sorry for that. I will not use that font in future videos

  • @josuetavares49
    @josuetavares49 Před 3 měsíci

    with this font it is difficult to read

  • @iJuce
    @iJuce Před 10 měsíci +3

    Why would you upload a video with that font 🤦🏽‍♂️ it’s so unreadable

    • @dev.channel
      @dev.channel  Před 9 měsíci

      Thanks for the feedback. I will remember to not use that :)