Unit Testing with Mocha and Chai [Part 1/2]

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ต.ค. 2024

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

  • @facelessvoid4657
    @facelessvoid4657 ปีที่แล้ว

    Awesome you did my day! Your video helped me with "function is not a function" error. Thank you very much!

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

    This is insanely clear and concise. You make life easy!

    • @codewithbubb
      @codewithbubb  ปีที่แล้ว

      Cheers! Hope you found it useful!

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

    Awesome ! Thank you. This video and the next one are exactly what I was looking for

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

      Great! Hopefully you'll be up and running with unit testing now!

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

    Thank you! I`ve been soo lost with other exponaitions,but yours is top!

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

    Awesome tutorials man, subscribed! Keep up the great work.

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

      Thanks very much Thomas! Hope you found it useful.

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

      a tip: you can watch movies at flixzone. Been using it for watching all kinds of movies recently.

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

      @Trace Tate yea, I have been using Flixzone for since december myself :)

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

    Great video. I was exactly looking for this

    • @codewithbubb
      @codewithbubb  ปีที่แล้ว

      Great! Hope you found it useful?

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

    Amazing tutorial!

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

    Thank you so much! You explained it like a pro!

  • @isaacciliaattard5625
    @isaacciliaattard5625 9 หลายเดือนก่อน +1

    Legend!

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

      Thanks very much!

  • @dankipruto3727
    @dankipruto3727 8 หลายเดือนก่อน +2

    I am getting this error when I import the expect function from chai and run it "Error [ERR_REQUIRE_ESM]: require() of ES Module /home/dan/Documents/mocha/node_modules/chai/chai.js from /home/dan/Documents/mocha/test/indexTest.js not supported.
    Instead change the require of chai.js in /home/dan/Documents/mocha/test/indexTest.js to a dynamic import() which is available in all CommonJS modules.
    at Object. (/home/dan/Documents/mocha/test/indexTest.js:2:18)". How can I fix it? Thank you

    • @ryanford516
      @ryanford516 4 หลายเดือนก่อน

      In order to fix this, you've got to do two things. Firstly, replace the lines const assert = require('assert'); and const { expect } = require('chai'); with just one which is import { assert, expect } from 'chai'; Next open up your package.json file and pop the following line just above your "scripts" property: "type": "module"

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

    very good video

    • @codewithbubb
      @codewithbubb  4 ปีที่แล้ว

      Thanks for your support!

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

    Nice intro! And SMH, I've been calling 'nyc' (nice) as 'New York City').
    Where do enzyme and sinon come into play?

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

      I think 'New York City' is much cooler 😀Sinon is for stubbing which we go through in this video (th-cam.com/video/gD4Sg3OuMiA/w-d-xo.html) Enzyme is for React projects.

  • @danialabd7473
    @danialabd7473 ปีที่แล้ว

    Would've been nice if the video wasn't only on 360p! hehe

  • @BEEHeebakhan
    @BEEHeebakhan 3 หลายเดือนก่อน

    Whenever I am trying to run my test using npm run test, it is giving me ES module scope error. I am stuck with it since yesterday but still can't find solution.
    I have tried everything : from including type: module in package. Json to naming files with .mjs extension and what not.
    Please tell what should I do to run my test without any module error

  • @Tiago-rw8cx
    @Tiago-rw8cx 2 ปีที่แล้ว

    How can you have the terminal lines:
    "at Context..."
    "at process.."
    in light grey font color?
    They show in aggressive red on my default VScode window and it is so much worse. Thank you very much!

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

    I have a question. When we use chai, do people
    usually do [ expect().to.be() ]
    instead of [ assert.equal(,) ] ??
    I just want to know which is the more common style.
    Thanks,
    I’m really grateful for a great tutorial for javascript testing.

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

      that's the basic case, i suppose expect has more methods to compare than assert.

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

    how can we write test cases for function that does not return any thing? I mean in this video you have used add and sub, so they return either a+b or a-b. What if i dont return a+b and rather store it in a variable. How do you prepare test for that?

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

      Depends on what the function does - is it calling other functions (you can check that they get called by spying / stubbing them) or does it create a side-effect elsewhere (you can check that the update has gone through).

  • @aarondz789
    @aarondz789 4 ปีที่แล้ว

    谢谢分享.thanks.

  • @_.sunnyraj._
    @_.sunnyraj._ 4 ปีที่แล้ว +1

    Is the stripe tutorial not ready yet ?

    • @codewithbubb
      @codewithbubb  4 ปีที่แล้ว

      It's on my todo list, been busy at work recently so apologies about the delay😢

    • @_.sunnyraj._
      @_.sunnyraj._ 4 ปีที่แล้ว

      @@codewithbubb I have completed that leave it now

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

    how can we type-check the code?

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

    When I write npm run test it gives an error saying mocha is not defined as internal or external command.HElp??

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

      Make sure you got Node installed. then run "npm init -y". Then you can run "npm install --save-dev mocha". Then create a folder in the root of your project (same level as package.json) called "test." Then go into package.json and change the value of the "test" property to "mocha test". Then run "npm run test" into your command line. You should see a failing test. Then just follow the video from there.

  • @adevtv05
    @adevtv05 ปีที่แล้ว

    See shorts about positive test using mocha for rest API here: th-cam.com/users/shortsrWEB0NXjoBU