Unit testing in JavaScript Part 2 - Your first tests

Поділитися
Вставка
  • Опубліковано 27 жов 2024

КОМЕНТАРІ • 206

  • @ddanielsandberg
    @ddanielsandberg 7 років тому +257

    The main reason to write tests first (TDD) is that the test becomes the first client/user of that code, or more specific; the first client of that API. If the tests are easy to understand the API is probably good. When I started out with TDD I ended up in situations where I felt like "the tests doesn't let my write the code I want to write, this is stupid!". It was only later I realised that my designs, code and APIs was s*it and I should listen to the tests telling me that. If tests are hard to write, the design is either bad or I'm writing some horrible integration code (filesystem, network, db).
    The other reason to have a test failing before writing the implementation is to ensure the test is testing what you think it is.
    For example, making the code just throw an error to "make the test fail" would be missing the point. It's not the test that is failing, it's the implementation that fails the test. I would suggest having the test tell you what went wrong: i.e "Expected a total of: 808, was: 0". Now we can see that we are testing for the case we think we are. In the end it's really about building confidence in the tests.

    • @funfunfunction
      @funfunfunction  7 років тому +25

      What a great comment, thanks!

    • @JeremyAndersonBoise
      @JeremyAndersonBoise 7 років тому +14

      Daniel Sandberg Seriously; That’s a better summary than most entire books on the subject. Bravo!

    • @SoldeplataSaketos
      @SoldeplataSaketos 7 років тому +6

      Frameworks like Mocha can do a lot of that for you. Remember: programming was born to automate boring tasks... like executing all the tests!

    • @michaelerwin8744
      @michaelerwin8744 6 років тому

      Ha ha. Your comment reminded me about the phrase "it all boils down to confidence" - the main slogan of AdonisJs which happen to be the framework I'm learning right now. Very good explanation.

    • @codebubble7478
      @codebubble7478 6 років тому +1

      Well said. To add to that: Jest shows what's received and what's expected :)

  • @FairyRat
    @FairyRat 2 роки тому +44

    The Odin Project once again sent me for your channel. You have a real way with words, extremely helpful as always.

    • @hackmaster6109
      @hackmaster6109 Рік тому +2

      He left the channel though :(

    • @noctis_rune
      @noctis_rune 3 місяці тому

      @@hackmaster6109 he is back!

    • @DenVIII
      @DenVIII 2 місяці тому

      @@hackmaster6109 and now he's back again :)

  • @KimHogeling
    @KimHogeling 7 років тому +39

    These 23 minutes felt like just 5. This is done really well and improved my perspective towards unit testing! Can't wait for next episode :)

  • @JefersonEuclides
    @JefersonEuclides 7 років тому +3

    When I started unit testing I always felt like I was doing if(true) true; if(false) false; And that made me feel like I was just wasting my time. After a few hundreds lines of tests I definitely felt like I was secure, like the API was secure against myself, my own mistakes. The felling of running npm tests after a major update and knowing that everything is fine (without hours of postman tests) is priceless.

  • @paigedumplings2570
    @paigedumplings2570 2 роки тому +3

    Here from The Odin Project - love your videos and your teaching style! You make it both educational and fun :)

    • @mo.G_2020
      @mo.G_2020 6 місяців тому

      He quit YT, so sad

  • @NixAlaister
    @NixAlaister 7 років тому +67

    "Rocket Surgery" - Love it!

    • @funfunfunction
      @funfunfunction  7 років тому +3

      first heard it from DHH so I can't take credit, but it is a great term!

    • @NixAlaister
      @NixAlaister 7 років тому

      Good old DHH!

    • @josephdburdick
      @josephdburdick 7 років тому +1

      New band name.

    • @ThomasLe
      @ThomasLe 7 років тому

      Orthodox-ness is a good one too! :D

    • @uhl7792
      @uhl7792 7 років тому

      This is called a Malaphor, they're super fun, highly recommend looking up some more! malaphors.com/

  • @sweeball
    @sweeball 7 років тому +1

    Thanks mpj. I like the introduction to the concepts without the use of a test runner. It demonstrated that one can write test by employing just plain old vanilla JavaScript. Look forward to next Monday!

  • @ibetovski
    @ibetovski 7 років тому +5

    MPJ, this video is great! Congratulations for splitting the unit tests theory from using test runners.
    One of the mistakes every newcomer can make when starting doing unit tests is to test the unit's implementation instead of input->output confirmation.
    When I started I tested every property of a class if it exists and if it is a certain type. One hour later I realized my mistake.
    I hope you will mention the mocking and stubbing in the next videos and if it is a code smell or not.
    Good luck :)

  • @humberjini1994
    @humberjini1994 7 місяців тому

    8:04 is why your video series is so great. Having a blast learning from you, thanks!

  • @jalalchachoua6370
    @jalalchachoua6370 7 років тому +45

    this guy is genius, or should I say these guys :D

  • @marekk1643
    @marekk1643 7 років тому

    You, sir, are a godlike teacher. Explaining concepts instead of showing bland code in a specific framework really makes every second worth watching you. Hope you make it as a full time youtuber. Cheers

  • @simoneicardi3967
    @simoneicardi3967 7 років тому

    Thank you very much MPJ! I'm just approaching unit testing and these videos are very useful to me. Love your "unit explanation way", so it's very easy to understand everything without having over-information. Keep doing it!

  • @naderabdelrahman
    @naderabdelrahman 5 років тому +1

    The soup analogy was great, very helpful

  • @taaemoh
    @taaemoh 7 років тому +2

    I really like the soup example, very thoughtful

  • @leonardodiasdevasconcelos8627
    @leonardodiasdevasconcelos8627 7 років тому

    MPJ: Multiple Personality Javascript-master.
    Loved the new idea of "different people" asking questions and commenting as you explain things.

  • @Joelasaur1
    @Joelasaur1 7 років тому +3

    Last week I was anticipating that this episode would be a Mocha walkthrough or some other test runner suite. Guess I'll have to wait until next Monday, I hope you don't take Thanksgiving off.

  • @J.C.Schartau
    @J.C.Schartau 7 років тому +1

    Really like your new format MPJ! Looking forward to episode 3 💡

  • @vikai_fang
    @vikai_fang 7 років тому +4

    Great show, any other hosts would make this topic way too boring, but not you! :) Thanks a lot.

    • @funfunfunction
      @funfunfunction  7 років тому +3

      Thank you so much for saying this, I spend a lot of time on making sure that the content keeps your attention.

  • @JeatBunkie
    @JeatBunkie 2 роки тому +1

    You are a genius teacher. Oh my god, I am going to gain so much from this channel I am so glad I found this today 💛

  • @emilaasa
    @emilaasa 7 років тому +1

    Strong pedagogy! I like the fact that you did not use a test-runner!

  • @theophile_
    @theophile_ 7 років тому +8

    I think we have a little editing mistake at 3:37, the sunglasses MPJ repeats himself !

  • @Patrick-yu2et
    @Patrick-yu2et 7 років тому +10

    Man this intro song is awesome!

    • @k12i
      @k12i 6 років тому +1

      curious about the song name!

  • @BokoaChocobo
    @BokoaChocobo 6 років тому +2

    What you meant by every test being a unit, could be seen in the Single Responsibility principle, automated tests are also software, hence, best practices still are tied to them, a single test that tries to test the whole API of a component will be probably harder to maintain, way more fragile, and harder to understand. Also, some of us believe that unit tests can be used as part of the documentation, single tests that tell you exactly what certain functionality of the component does could help you a lot when you are working on code you have never touched before.

  • @jkeum3
    @jkeum3 7 років тому +3

    YESSSS!! I waited for this video all week!!!

  • @jeffwells641
    @jeffwells641 6 років тому

    I just had an epiphany about unit testing and why it works. I've been working through an all-inclusive programming textbook called 'All of Programming', and in it they lay out the entire process for writing an algorithm from start to finish in great detail in a sort of old-school, traditional, tried and true way. The start is defining a problem, then solving one instance of that problem (without writing any code), then making that solution general enough to solve every instance of the problem that is within your scope, and finally writing the code version of that solution to form the algorithm.
    Well, unit testing is basically a way of working through the problem to find the solution in parallel to writing the algorithm. It's like combining the two steps without losing the benefits of either. The test is basically solving the problem, and then you write code that satisfies the test. Bonus is that you've automatically got something that verifies things like your old code working with your new code, which you showed in the video. Pretty cool, IMO, and not the way I used to think about TDD. Definitely seems like something I should learn.

  • @johncarloadamos9472
    @johncarloadamos9472 4 роки тому

    The soup example is very good. Subscribed.

  • @davidnagli
    @davidnagli 7 років тому +3

    Hey MPJ, you should really talk about Ava in your next episode. It's a really awesome and modern concurrent test runner for JavaScript, and I really think that your audience would love an episode about it!

    • @funfunfunction
      @funfunfunction  7 років тому +2

      Sorry, Ava is way too much magic, future and thingees to introduce at this point. The purpose of this series is to teach unit testing in the most down to earth and straightforward manner possible.

    • @davidnagli
      @davidnagli 7 років тому

      Fun Fun Function, That makes allot of sense. I noticed in some of the other comments your gonna be using Jest which is also a really awesome framework. I actually agree the Jest is easier for beginners since it has much better documentation.

  • @MatthewPeck_personal
    @MatthewPeck_personal 7 років тому

    Self-taught JS developer here. Gotta say man, your videos are amazing and help me fill in some of my own skill gaps. Awesome videos!

  • @CarsonLourenco
    @CarsonLourenco 7 років тому +5

    (Disclaimer: Mildly drunk right now, so excuse any poor grammar)Hello!! I haven’t watched this video yet but I want to say something on your latest video so that you might see this comment. Anyway, just wanted to thank you on your insights and advice through all your videos!! I’ve recently taken on a project that is probably slightly out of my depth and while your videos haven’t completely given me every answer I need, they have definitely helped with how I approach the problems at hand, and have given me things to consider I wouldn’t have otherwise considered, so thank you :D

  • @willl0014
    @willl0014 3 роки тому

    This videos are gold! Not only how but why! Just Big props for the excelente content

  • @manuelramos5869
    @manuelramos5869 6 років тому

    First time I see it that clearly. Thanks a lot! You are very good!

  • @acushlakoncepts
    @acushlakoncepts 4 роки тому

    You look like Tony Stark on those glasses, I enjoyed every bit of your tutorial

  • @komicproductions3887
    @komicproductions3887 6 років тому

    Describing why write tests first using a cooking example -> Pressing Like button instantly :)

  • @louisvno7649
    @louisvno7649 7 років тому

    Haha yeaa recognizable this "archeology" feeling of having to dig up the usecases from code to write tests. This vid def has made me want to try out tdd!

  • @JohnnysaidWhat
    @JohnnysaidWhat 4 роки тому

    glad i'm watching this in the future

  • @Patrick-yu2et
    @Patrick-yu2et 7 років тому

    Actually this whole intro is awesome!!!!

  • @sylvain1099
    @sylvain1099 7 років тому

    The guy with the sunglasses asks the same questions than me. Hopefully the guy with the hat answers perfectly ;) - Keep doing your videos, it's really good

  • @ФедорМорев-г3ш
    @ФедорМорев-г3ш 6 років тому +3

    Could you please tell what is the plugin (or smth.) you use to get results right down in your text editor?

  • @YourCompanyCTO
    @YourCompanyCTO 2 роки тому +2

    How do you make those inline errors popout? What editor do you use?

  • @ayushgp1
    @ayushgp1 7 років тому

    Great video MPJ! Thanks!

  • @B16B0SS
    @B16B0SS 7 років тому +1

    Really enjoy your videos.

  • @esaius2058
    @esaius2058 Місяць тому

    That beat at 15:08 goes hard!!

  • @olegloutchansky1290
    @olegloutchansky1290 7 років тому

    I know all about Unit tests, but this video awesome and very interesting 👍

  • @SergiuMunteanu
    @SergiuMunteanu 7 років тому

    I hope the next episode is about testing different types of react component :)

  • @bgvianyc
    @bgvianyc 7 років тому

    A good topic down the road would be which testing strategies to use on the front-end. Unit testing only goes so far on the front-end.

    • @funfunfunction
      @funfunfunction  7 років тому

      Great suggestion. We have fantastic options for unit testing frontend today compared to just a couple of years ago, and I don't think many people realise that.

  • @riskitall7421
    @riskitall7421 2 роки тому +1

    @7:53 I'm dying right now LMFAO

    • @dansmar_2414
      @dansmar_2414 2 роки тому

      oh my God, this is very funny hahaha

  • @kristoffergonzaga5531
    @kristoffergonzaga5531 7 років тому +14

    MPJ, what extension do you intall for that "showing error thing" on your vscode?

    • @kristoffergonzaga5531
      @kristoffergonzaga5531 7 років тому +4

      ariefrizqon thanks!

    • @Tronoslycer
      @Tronoslycer 5 років тому

      @@kristoffergonzaga5531 what about ajax calls?, when I write ajax calls it execute the function inmediately?

  • @darioasaro6902
    @darioasaro6902 4 роки тому

    Hello from Argentina MpJ,you are really awsome

  • @madhusuthananThedeveloper
    @madhusuthananThedeveloper 7 років тому +3

    I like the mono acting. Was a treat to watch.🙂 But this was a great explanation in layman's term on why to write test first. Kudoj @mpj

  • @samerkayali4525
    @samerkayali4525 4 роки тому

    Aewsome content!! congrats!

  • @leo12345639
    @leo12345639 7 років тому

    love this series so much

  • @kevinb1594
    @kevinb1594 7 років тому

    Thanks MPJ! I really hope you hit on Mocha/Chai next week! (I dislike the other test runners) Something I also hope you explain is which parts of the application should be tested and how to deal with code that requires external resources. I always run into a brick wall when I get to database dependent code and no idea how or even if you should test code connected to the UI or that requires user interaction.

    • @funfunfunction
      @funfunfunction  7 років тому

      Yeah, mocking dependencies is definitely something that we'll be spending a lot of time on. I am sorry to be disappointing you though - we'll probably be using Jest, as it's what the React team pushes, and also has the huge pedagogical benefit of having mocking, expectations and test runner bundled into one.

  • @ВениаминТрепачко
    @ВениаминТрепачко 6 років тому +1

    Song:
    Jules Gaia -- Glitz at the Ritz

  • @grdalenoort
    @grdalenoort 7 років тому

    An item object in the example is a flat standard object, not a first class object. It is much easier to validate a value-object. e.g. if an item would be a class with predefined properties. (name, quantity, price), then you can easily validate it when creating an item. The tests for your order class can then always expect that an item is valid. That way you can focus on validating the order process.

    • @funfunfunction
      @funfunfunction  7 років тому

      Yes. However, that is fixating on a detail with the example rather than the point I was trying to illustrate, which is that the tests warn you when you are breaking your API contract. Try imagining that this, instead, was a REST service accepting a JSON object instead.

    • @grdalenoort
      @grdalenoort 7 років тому

      Nice, yes. But even then (nerd-hat-mode) you would scoop the flat objects into item objects and validate input, and then still be able to fail early on errors :-) Also, i'm more server-side (php) programming, but love your videos and learn a lot from them, so no hard feelings. Thanx

    • @PeerReynders
      @PeerReynders 7 років тому

      Just because there is an “object” doesn’t automatically imply that it needs a class to manage it - unless one subscribes to OO dogma. It’s not uncommon in JS that objects are simply used as hashmaps/dictionaries (though ES2015 actually has a proper Map object (and even Set)). The opening episode “Higher-order functions” of this channel should make it clear where the channel’s loyalties lie.
      Pure functions are easy to test - methods exist for side effects on their instance either by reading or mutating it so they can only be tested in the presence of an instance and it’s state - and in most cases mutability is a feature of instances when it needs to be something that is handled with diligence.
      Classes are useful in some cases but they really don’t need to be the default. For example validation on creation can easily be handled by “factory functions” (for example, search online: “JavaScript Factory Functions vs Constructor Functions vs Classes”).

  • @hermeschi
    @hermeschi 2 роки тому +1

    What VSCode extension shows the error and output out like that

  • @tpdopitz1577
    @tpdopitz1577 6 років тому

    Thanks for that great explanation. Nevertheless I'm missing some important points: In theory there is a difference between _TDD_ and _test first_ ( _TDD_ is a special case of _test first_ ). IMHO your video would have benefit from not mixing these terms. Then: TDD-Cycle has *3* Steps: red/green/ *refactor* . The last one is really important to produce really clean code. Hope you create an episode about that soon.

    • @funfunfunction
      @funfunfunction  6 років тому +1

      Hi tpd! Thanks for your feedback. I intentionally tried to avoid both the terms test first and tdd and just show the concepts themselves because whenever I use specific terminology the discussion becomes about the definition rather about what we are trying to acheive. Sorry if I let something slip there. The refactor step gets added later in the series, we cant cram everything about unit testing into one video. :)

    • @tpdopitz1577
      @tpdopitz1577 6 років тому

      Hi MPJ.
      > _"I intentionally tried to avoid both the terms test first and tdd"_
      But you failed... ;o)
      I see your point but I believe that clear communication is important, especially if you want to teach something. The difference between _test first_ and _TDD_ is somewhat essential. And since it is hard to talk about unit testing while avoiding these terms (as your video proves...) they should be explained.

    • @funfunfunction
      @funfunfunction  6 років тому +1

      Yeah, again, sorry. Either way, try to disregard it. It's really not what we're aiming for here. We are not looking to explain the exact defintions of these, we're trying to make people "get" the why and what concept. Definitions aren't particularly important at this point in the learning phase - the same reason we're not getting into the definitions of stubs/mocks/doubles. Don't get me wrong, definitons are great but the perfectly succinct definition "monads is just a monoid in the category of endofunctors" is just not a good place to start out - it's better to start showing some monads, maybe even without even using the word monad, and later introduce the general concept.

  • @injectjon7240
    @injectjon7240 7 років тому +1

    11:00 "yah - they are getting it"

  • @djcardwellai
    @djcardwellai 3 роки тому

    wish this guy still did videos

  • @80Vikram
    @80Vikram 2 роки тому

    14:59 what's the background music called ? Is there a playlist for such happy background music ? It's like 30s, 40s Charlie Chaplin movies background. Thanks for great content anyways. God bless you.

  • @phuclehong3291
    @phuclehong3291 3 місяці тому

    tks u, but i have a question. What is the ide or text editor that you are using so that when the error is thrown?

  • @pyc0d3r
    @pyc0d3r 6 років тому

    Thank you sir i got it on you descriptions

  • @entrptaher
    @entrptaher 7 років тому

    I was going thru Testing related materials, and boom, you released a video about it.
    Now, let me travel to next monday using my time machine that I wrote the tests for. It should work, right? Cause I made tests for it....Right?

  • @andrejlezmann1297
    @andrejlezmann1297 5 років тому

    Big Thanks for the fun fun fun

  • @80Vikram
    @80Vikram 2 роки тому

    17:59 I didn't get how are you running this ? Please clarify

  • @noelsoong777
    @noelsoong777 6 років тому

    I got into a company that hired me after i graduated. They made me do unit tests for already written programs and it got hard to imagine what to do. More tests pile up and i get blamed for it.

  • @mikkqu
    @mikkqu 6 років тому

    What is not quite clear from the video is how thorough the tests should be.
    - Should we have a test for missing 'name' property?
    - Should we have a test to make sure that every single item has 'name' property?
    - Should we have a test for negative quantity values?
    We might end up having 50 unit tests for the function that's only 5 lines long.
    Like, what is the borderline? I would like to see a little comment on this question.

    • @funfunfunction
      @funfunfunction  6 років тому +1

      Sorry if it's unclear, I try to explain in the series, but here it is again: We write a test in order to drive behaviour. We don't test code per se, we write a test in order to enforce that the code does what we need it to do. For example, do you want your function to handle negative quantity values, or fail if it gets one? If so, write a test for that, make sure it fails, and then write code to make the test pass. This is the power of the test-driven approach, we only write code if it's required to make a test pass.

    • @mikkqu
      @mikkqu 6 років тому

      Oh, this makes sense. Thanks!

  • @ebukaume
    @ebukaume 5 років тому +1

    Please, what is the name of the extension that runs your code as you write them?

    • @DrDemolition
      @DrDemolition 3 роки тому +1

      I'm a year late but it's in the description. Quokka!

    • @ebukaume
      @ebukaume 3 роки тому

      @@DrDemolition thanks

  • @karolekkarolek1596
    @karolekkarolek1596 7 років тому

    How do you go about testing in browser js code? Do you create a test page, including the tests? Tbh there is almost no info on how to write this type of tests.

  • @jamesshadrack3172
    @jamesshadrack3172 День тому

    The Odin Project sent me here on this day

  • @Chocoholic1337
    @Chocoholic1337 7 років тому

    I'm sure this gets asked way too often, I haven't been able to find it in the comments but..
    What editor are you using, that displays the JavaScript errors in-line? It seems very useful!

  • @j3bb9z
    @j3bb9z 7 років тому

    Hey, would you consider making video about FRONT END LOGGING (or at least make an advice here, in the comments? :) )?
    Unfortunately, this topic is often completely ignored. I know there are plenty of SaaS solutions... but should we go with one? I guess they don't do the hardest part - actually catching the errors. I was thinking of using some library to catch all errors (but how to catch all uncaught errors in all browsers?!) and send them to backend service and then put in log files. And maybe make some aggregation/deduplication on the way? That way we could put it in the same system as backend ones.
    By the way - thanks for your amazing videos!

  • @dwakeling1
    @dwakeling1 5 років тому

    I dont think youve mentioned in the videos or bio, what testing library you are using.

  • @RobertBMenke
    @RobertBMenke 7 років тому

    What's that electro swing jam that he plays while he does the fast motion working scenes?

    • @funfunfunction
      @funfunfunction  7 років тому +1

      It's Glitz at the Ritz, Jump Jive Roar, and Let's Bounce!

    • @AlexToder
      @AlexToder 7 років тому

      How did you find this song and you bought license for it ?

  • @paligamy93
    @paligamy93 6 років тому

    Put down a time if i'm wrong but unit testing is about defining behaviour. I didnt see anything that actually should fail. If im testing say a reciprication function that takes in a fraction, if you give me a 0/4 I had better fail in an expected way or have it documented as undefined behaviour. especially for checked and unchecked function pairs for pre conditions

    • @funfunfunction
      @funfunfunction  6 років тому

      I'm sorry, I don't really get your question, can you elaborate?

    • @paligamy93
      @paligamy93 6 років тому

      Sorry for the incoherent thoughts haha
      I did not see you checking that a function "fails properly".
      If you have a function, for example, throws some exception when a pre-condition isn't met, then you should check that the function is behaving properly and make sure that you're catching that throw in some test because that is how that function behaves.
      You ought to be testing all the behaviors your function will produce, including throwing or documenting undefined behavior if the end behavior can't be predicted.

  • @agborblessing2367
    @agborblessing2367 2 роки тому

    Can we use Switch cases in place of If conditions ?

  • @lallenfrancisl
    @lallenfrancisl 2 роки тому

    These are incredibly well made 🫡

  • @lnplum5404
    @lnplum5404 6 років тому

    Is it just me or is there a bug in the code? Quantity zero is treated as unspecified quantity, so it counts as 1.

  • @ThomasLe
    @ThomasLe 7 років тому

    I was just hired as a Jr. Software Dev and I do freelance on the side. I made a decision a month or two ago that for my freelance clients I will always do unit testing and it wont be a negotiable item (if it adds time/cost or not).
    A programmer friend of mine and my new employer both have said that clients sometimes(read:most times) don't understand or care about the benefits of unit testing and sees the bottomline.
    Do you think this is a good policy to have, always do unit testing for freelance clients ?

    • @funfunfunction
      @funfunfunction  7 років тому +3

      I was thinking about this a few months ago. There is a LOT of quality-related things that you can skimp on in a software project. Unit tests is one, but backups, monitoring, error logging, and code review are other examples. These can all be skipped in order to deliver more things in fewer hours, but instead you're paying in higher risks and (much) larger maintenance costs once the codebase grows older than 6 months of development or so. Often, this is invisible to the client, especially one that doesn't know the benefits of these techniques. I was thinking that whatever is part of the quality package could be made part of the sell - i.e. list all the quality work that your consultancy does, and explain in clear terms what the benefit is to the client in business value, and encourage the client to ask your competitors if they include this in their offerings.

  • @riskitall7421
    @riskitall7421 2 роки тому

    Wonderful information.

  • @pyc0d3r
    @pyc0d3r 6 років тому

    Please sir with addon are you using on visual studio code when you write a function or code its show you the output (left red words) thankyou

    • @funfunfunction
      @funfunfunction  6 років тому

      quokka.funfunfunction.com

    • @pyc0d3r
      @pyc0d3r 6 років тому

      Fun Fun Function Thank you sir You save my ass🤩😍😎

  • @taaemoh
    @taaemoh 7 років тому

    what's the name of that plugin u use which displays live error message in red?

    • @davidnagli
      @davidnagli 7 років тому

      Tameem Zaaiter see episode description

  • @DDoesT
    @DDoesT 4 роки тому

    We miss u mpj

  • @fabiocarpinato
    @fabiocarpinato 7 років тому

    When i started using the TDD pattern i was really bored, and i tought that it was stupid, now i can't write a single line of code without writing a test first, its so hard to develop without something that ensure you that you are writing code for the right reasone and not just becouse you think its right.

  • @jethrolarson
    @jethrolarson 7 років тому

    You going to cover property-based testing at some point?

    • @funfunfunction
      @funfunfunction  7 років тому

      Probably not in this series. I'm not convinced of it's usefulness. (Not saying that I'm convinced it's useless either, it's just that no programmer I respect has advocated it to me yet)

    • @jethrolarson
      @jethrolarson 7 років тому

      Yeah. I'm sorry to find so little press about it, especially in JS. I will mention that leebyron.com/testcheck-js is made by Lee Byron and seems pretty great.

  • @thatguynar
    @thatguynar 6 років тому

    What vscode xtension is he using that shows the errors inline?

  • @SirKnico
    @SirKnico 7 років тому

    What IDE is being used here to automatically check the tests inline?

    • @funfunfunction
      @funfunfunction  7 років тому

      See episode description!

    • @SirKnico
      @SirKnico 7 років тому

      Ahh thank you! I missed it first time

  • @xochitlselene7312
    @xochitlselene7312 4 роки тому

    Which text editor is that one?

  • @navroze92
    @navroze92 6 років тому

    Hi MPJ, really insightful, I am going through the phase of starting TDD. There is one challenge I encountered, may need your or the audiences help on it. So we know that we are performing unit testing on a function. But what happens in the case when there are two independent use-cases in the function. Example one use-case will calculate the sum, the other use-case will retrieve data from the database.These are two independent use-cases which reside in the same function but I want to test them against the function that I have created as a whole. How can this be achieved.

    • @funfunfunction
      @funfunfunction  6 років тому

      Can you please post some code? It's hard to tell why you simply cannot just write two tests.
      From your description, it also seems like the function might be doing too much work and should be two functions.

    • @navroze92
      @navroze92 6 років тому

      My code would look somewhat like this
      function getLinks() {
      let data = await db.link.find({id:"abc"});
      let result = a + b;
      result > 5 ? return data: return NULL;
      }
      I want to create a test case to check if my data.length > 0 and then based on the condition result > 5 and then it should test against the data(not concerned with this) that I have retrieved from the DB.

    • @funfunfunction
      @funfunfunction  6 років тому

      Where does a and b come from?

    • @navroze92
      @navroze92 6 років тому

      They are passed as function args. Sorry I forgot to add that to the function. Any who I just wen through your dependency injection video and got a much clearer picture on how this can be achieved. Will start implementing that. Thanks :)

    • @mikeyrt16
      @mikeyrt16 6 років тому

      (1) Mock your db call, either with manual mocks or a mock function (I'm using a mock function in the example).
      (2) You want to test the expected behaviour of the code from the perspective of it's api.
      --- Example (Jest) ---
      test('getLinks returns data if sum is > 5', () => {
      db.link.find = Jest.fn(() => 'TEST DATA')
      expect(getLink(2, 4)).toBe('TEST DATA')
      })
      test('getLinks returns null if sum is

  • @pluraltest9242
    @pluraltest9242 7 років тому

    how are you writing the test what tool is this if it isn't jasmine/mocha

  • @Azerty777
    @Azerty777 7 років тому

    Hey, what IDE are you using please?

  • @rja421
    @rja421 7 років тому

    I am hoping that you cover using Jest.

    • @funfunfunction
      @funfunfunction  7 років тому +2

      yep, thats definitely in the plans

    • @davidnagli
      @davidnagli 7 років тому +1

      No!!! Use Ava, it's so awesome... (or do both)

    • @rja421
      @rja421 7 років тому

      Awesome, thanks!

    • @PeerReynders
      @PeerReynders 7 років тому

      Tape is on the other end of the spectrum. For some interesting opinions regarding the choice of testing tool - search online: “Why I use Tape Instead of Mocha & So Should You”.

  • @KevinOsterkilde
    @KevinOsterkilde 7 років тому +1

    Blooper at 3:37 ;)

  • @duvu9760
    @duvu9760 2 роки тому

    Thanks so much

  • @riskitall7421
    @riskitall7421 2 роки тому +1

    Triiiiiiiiiiiangulation LMFAO

  • @codezero6023
    @codezero6023 7 років тому

    Definitely use Istanbul too. Nothing a good tool for showing missed code paths.

  • @Patrick-yu2et
    @Patrick-yu2et 7 років тому

    Hey mpj, what are your thoughts on injecting dependencies through factories as you usually do on videos VS stubbing the modules returned by the require in nodejs ? (like explained in this so answer stackoverflow.com/a/16308099)
    I personally think that stubbing the required module is to much magic and it will come back in my ass anytime soon, plus sending dependencies in through factories makes everything explicit

    • @funfunfunction
      @funfunfunction  7 років тому +1

      Not a fan personally, and I don't agree dependency injection harms code simplicity - it's specifically targeting code simplicity (I think a lot of people confuse terseness with simplicity which is completely different). The notion that introducing a sophisticated magical tool like proxyquire into your toolchain just to avoid passing dependencies would be a more simple solution is pretty ludicrous.
      If you're a patron, there is actually a fantastic topic on the Fun Fun Forum about this specific topic here: www.funfunforum.com/t/why-i-dont-like-dependency-injection-in-javascript/2406

    • @Patrick-yu2et
      @Patrick-yu2et 7 років тому

      Thanks for taking the time! I'll take a look =]

  • @daniellaerachannel
    @daniellaerachannel 7 років тому

    and what about devtips??

  • @MadEye27
    @MadEye27 7 років тому +1

    Dude, what's up with your pen? This is some pen for penspinning?

  • @martinnjoroge9789
    @martinnjoroge9789 4 роки тому

    I shall bestow a new name on thee. 'Split the Coder'. Due to the multiple personalities he has.

  • @ivanhoe011
    @ivanhoe011 7 років тому

    Well, one can write tests immediately after finishing each piece of code, it's not like you have to wait a week to do it... it takes exactly the same amount of discipline as writing them first...

    • @JeremyAndersonBoise
      @JeremyAndersonBoise 7 років тому

      ivanhoe011 Maybe that’s true for you, but I submit you may be in the minority in that regard. Writing tests after the fact feels like doing one’s own code reviews. Fine if you are by yourself, and a superhero of some kind.