[OBSOLETE]: Suitest is a powerful and easy-to-use JavaScript unit test suite
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
HISTORY.md
MIT_LICENSE.txt
README.md
package.json
suitest.js
test.js

README.md

Suitest

Suitest is a powerful and easy-to-use JavaScript BDD test suite

  • Very simple to use
  • Minimum functions and maximum capacity
  • Client-side and server-side (including Node.js) support
  • One of the most lightweightest libraries for unit testing
  • Support for working with asynchronous code
  • Outline function callbacks!
  • Modular system
  • Fluent interface support (chaining)

####BDD practices:

Behavior-driven development (or BDD) is an agile software development technique devised by Dan North as a response to the issues encountered teaching test-driven development.

The practices of BDD include:

  • Establishing the goals of different stakeholders required for a vision to be implemented
  • Drawing out features which will achieve those goals using feature injection
  • Involving stakeholders in the implementation process through outside–in software development
  • Using examples to describe the behavior of the application, or of units of code
  • Automating those examples to provide quick feedback and regression testing
  • Using 'should' when describing the behavior of software to help clarify responsibility and allow the software's functionality to be questioned
  • Using 'ensure' when describing responsibilities of software to differentiate outcomes in the scope of the code in question from side-effects of other elements of code.
  • Using mocks to stand-in for collaborating modules of code which have not yet been written

##Synopsis

Add a test to run

.test ( name, callback, [, context ] );

*A comparison assertion*
.exec ( x, [, y, operator ] );

*Register a callback to fix test result*
.done ( [ callback, context] );

*Add test description*
.describe ( description );

*Register outline function callbacks*
.get ( name );

*Throws an exception when test run and stop all next tests*
.stop ();

*A boolean assertion*
.is ();

*Register a final callback whenever all the tests have finished running*
.finish ( [callback, [total, filed, passed, time] );

Installation

Downloading

Choose one of the ways to download the Suitest:

npm

sudo npm install -g suitest

git

git clone git://github.com/monolithed/Suitest.git

zip/gzip

https://github.com/monolithed/Suitest/downloads

Server-side including

var Suitest = require('./suitest.js');

Client-side including

<script src="./suitest.js" type="text/javascript"></script>

Using

var unit = new Suitest('Module name');

Screenshot

Suitest

API

.test ( name, callback, [, context ] );

var unit = new Suitest;

unit.test('test name', function(unit) {
	unit.exec(true, 1); // true
	unit.done();
});

.exec ( x, [, y, context ] );

Using with one parameter:

unit.exec(true); // true

Using with two parameter:

unit.exec(true, 1); // true, because default operation is ==

Using with three parameters:

unit.exec(true, 1, '==='); // false, because true and 1 are not equivalent

.done ( [ callback ] );

Simple using:

unit.done();

Testing asynchronous code:

unit.test('test name', function(unit) {
	setTimeout(function() {
		unit.exec(true, 1); // true
		unit.done();
	}, 2000);
});

.describe ( description );

unit.describe('Test description');

.finish ( [callback, [total, filed, passed, time] );

unit.test('test 1', function() {
    this.exec(true).done();
});

unit.test('test 2', function(unit) {
   this.exec(true).done();
});

unit.finish(function(data) {
    console.log('Total:', total, 'Filed: ', filed, 'Passed: ', passed, 'Time: ', time);
});

// Total: 6, Filed: 2, Passed: 4, Time: 1.00

.stop ();

unit.stop();

.is ()

unit.exec(true, 1);
unit.is(); // true

.get ( name );

Outline function callback

var set = function() {
	return unit
		.get('test 6')
		.exec(true, 1)
		.done();
};

Simple using

unit.test('test', function(unit) {
	set(); // true
});

Using with asynchronous code

unit.test('test', function(unit) {
	setTimeout(set, 2000); // true
});

Function.prototype.bind / Function.prototype.call
Also you can use it without <get> method (but this not recommended):

var set = function() {
	return this
		.exec(true, 1)
		.done();
};

unit.test('test', function(unit) {
	set.call(unit); // true
});

Context

There're several ways to set the calling context

this

unit.test('test', function() {
	this.exec(true).done();
});

parameter

unit.test('test', function(context) {
	context.exec(true).done();
});

.get()

var set = function() {
	return unit.get('test').exec(true).done();
};

unit.test('test', set);

.call/apply/bind()

var set = function() {
	return this.exec(true).done();
};

unit.test('test', function() {
	set.call(this);
});

Chaining (Fluent interface)

var unit = new Suitest;

unit
.test('test 1', function(unit) {
	unit.exec(true, 1).done();
})

.test('test 2', function(unit) {
	unit.describe('test description').exec(true, 1).done();
})

.test('test 2', function(unit) {
	if (!unit.exec(true, 1).is())
		unit.stop();
});

Operators

== operator is used by default and for most operations, you can miss it:

unit.exec(true, 1);

You can also specify it explicitly:

unit.exec(true, 1, '==');

Other available operators:
===, !==, !==, !=, <, >, <=, >=, eq

Special eg operator for egal comparison. The internal comparison abstract operation SameValue(x, y), where x and y are ECMAScript language values, produces true or false (ECMAScript 5 9.12).

unit.exec(NaN, NaN, 'eg'); // true
unit.exec(0,   0, 'eg');   // false
unit.exec(-0, +0, 'eg');   // false
unit.exec('0', 0, 'eg');   // false

License