Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Doctest-JS. Write unit tests using comments in your code (github.com/supabase)
3 points by kiwicopple on Feb 22, 2020 | hide | past | favorite | 1 comment


Hey HN. This is a small but useful library for writing tests using JSDoc.

For example you can write:

  /**
   * Returns the sum of 2 numbers
   *
   * @example sum(1, 2)
   * //=> 3
   */
  export const sum = (a, b) => {
    return a + b
  }

And then this library will assert that the @example returns the correct code.

This has been super useful for us because it is cognitively easier to write/run the tests in the context of the function itself.

It's not very well tested with classes, but we are looking for any feedback and will continue to improve.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: