Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

standalone assertion libraries?

Tags:

javascript

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).

like image 782
user5321531 Avatar asked May 06 '12 16:05

user5321531


People also ask

What are assertion libraries?

Assertion libraries are tools to verify that things are correct. This makes it a lot easier to test your code, so you don't have to do thousands of if statements. Example (using should.js and Node.js assert module): var output = mycode. doSomething(); output.

What is assert NPM?

Definition and Usage The assert module provides a way of testing expressions. If the expression evaluates to 0, or false, an assertion failure is being caused, and the program is terminated. This module was built to be used internally by Node.


2 Answers

As of May 7, 2012

After some brief research, starting with the most minimalistic:

  • assert.js - port of node assert functions
  • jShould - QUnit extension
  • should.js - node library
  • expect.js - based on should.js, standalone
  • YUIPort - YUI libs but standalone
  • chai - node and browser, plugins inc. for JQuery
  • expectThat - CoffeeScript

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:

  • JQuery's QUnit
  • Mocha
  • Jasmine
  • js-test-driver
  • YUI Test
  • Sinon.JS

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.

like image 117
3 revs, 3 users 62% Avatar answered Sep 18 '22 12:09

3 revs, 3 users 62%


function assert(condition, message) {     if (!condition) throw new Error(message) } 
like image 27
Raynos Avatar answered Sep 19 '22 12:09

Raynos