Which JavaScript unit testing framework do you prefer?

I'm curious which unit testing frameworks people like. In particular, if you have experience testing asynchronous code, I'd love to know whether there is a best-in-class framework for that kind of thing as well as what are some best practices to unit test asynchronous code.

Did you find this post useful? Show some love!

I have been using Jest to test "pure" JS code and Vue.js.

Test functions can be async so you can do stuff like:

describe('getData()', () => {
  it('should get the data', async () => {
    const response = await api.getData()

So you can use async / await. In some cases I don't have direct control on the promises the tested call generates so I use flush-promises to get the results. This is an actual test I have for a component that uploads images (using uppy that internally uses promises to do it):

  it('should mock upload an image', async () => {
    const url = 'http://dummyimage.com/100x100'
    const uppy = {
      upload: jest.fn(() => {
        vm.onUploadSuccess({}, {}, url)

    wrapper.setData({ images: [image], uppy })
    wrapper.setProps({ autoUpload: false })

    const button = wrapper.find('button.upload')

    // 1. it should emit an empty input (to reset the value upstream)
    let inputEvent = wrapper.emitted('input')

    // triggers all the promises
    await flushPromises()

    // 2. it should emit the URL as the last input event
    inputEvent = wrapper.emitted('input')
Classic DEV Post from Jun 13

How do you make time for your dev/tech projects?

Question I was about to write a long post about how I'm unable to allow a part...

Follow @sudiukil to see more of their posts in your feed.
Nested Software
β€œOf course, you only live one life, and you make all your mistakes, and learn what not to do, and that's the end of you.” -- Feynman, Surely You're Joking
More from @nestedsoftware
JavaScript Frustration: Classes and Class Properties Transform
#javascript #react #propertiestransform #discuss
Currying in Haskell (With Some JavaScript)
#haskell #currying #javascript
Trending on dev.to
Memoization in a Nutshell
#explainlikeimfive #beginners #javascript
Securing your Node js api with JSON Web Token
#javascript #node #jwt
Would you contribute to a JavaScript OSS Project that uses static types?
#discuss #javascript #flow #typescript
Open source: Cookie notifier, MailChimp mod, Editable job listings & more
#showdev #opensource #webdev #javascript
Test Driven Development 101 and JS testing
#testing #javascript #jest #mocha
Automatic `nvm use`
#bash #node #javascript #linux
Making Snake Game With Javascript
#javascript #game #programming #fun
Can react be used as a utility full stack web app?
#react #discuss #javascript