27

I was nearly through porting YUI assertion modules to standalone libraries when the thought popped into mind that I should have perhaps asked on StackOverflow if this was necessary first. However I finished the libs:

YUIPort: https://github.com/gso/YUIPort

But thought I would duly ask as well. Are there any good quality standalone libraries of assert functions - these can be very useful, e.g., checking the validity of arguments passed to functions (can save a lot of time invoking the debugger).

user5321531
  • 3,095
  • 5
  • 23
  • 28
  • how about QUnit? a unit testing lib, but supports these...I don't know much about testing, all right? just suggesting. – Parth Thakkar May 06 '12 at 16:57
  • 1
    The libs linked to above are tested with QUnit - I was looking for a standalone library, without the baggage of a whole testing suite. Something that could be attached to a webpage. I think I decided http://chaijs.com/ was the grooviest of the testing suites. Assert.js https://github.com/Jxck/assert is more what I am looking for - not sure why I didn't just use this. – user5321531 May 06 '12 at 17:13

2 Answers2

28

As of May 7, 2012

After some brief research, starting with the most minimalistic:

I have to admit that I do tend to agree with a commenter on DailyJS:

I don't understand why everyone likes these wordy assertion libraries.

Although I'm not a CoffeeScript user, I do tend to gravitate towards the plain assert.js style syntax rather than all this chaining.

Features that these libraries are developing include:

  • plugable with the major test suites (saves having to switch between two libraries when coding)
  • coding server-side (node) and client-side without changing libraries
  • integration into the main web frameworks (e.g. JQuery)

Some of the major test suites include:

The major web frameworks often include their own test suites.

Logging wise, there is a discussion on libraries available. They don't, at a glance, seem to have caught up with server-side JS as of yet.

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
user5321531
  • 3,095
  • 5
  • 23
  • 28
  • The standard for logging seems to be log4j which was developed by Apache and became popular: [log4javascript](http://log4javascript.org/) - based on log4j, [log4js](http://log4js.berlios.de/) - API very simialar to log4j, [JavaScript Debug](http://benalman.com/projects/javascript-debug-console-log/) - plain wrapper for console.log. – user5321531 May 07 '12 at 12:44
  • [console.log-wrapper](https://github.com/cpatik/console.log-wrapper) - console.log wrapper – user5321531 May 07 '12 at 12:59
  • should.js is a nice library. – Robert Kusznier Jul 04 '18 at 10:03
24
function assert(condition, message) {
    if (!condition) throw new Error(message)
}
Raynos
  • 166,823
  • 56
  • 351
  • 396