What test framework did you use to test your nodejs applications

1) Mocha -

Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun

Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases

Simple Usage -
$ npm install mocha
$ mkdir test
$ $EDITOR test/test.js # or open with your favorite editor
In your editor:
var assert = require('assert');
describe('Array', function() {
  describe('#indexOf()', function() {
    it('should return -1 when the value is not present', function() {
      assert.equal([1, 2, 3].indexOf(4), -1);
    });
  });
});
Back in the terminal:
$ ./node_modules/mocha/bin/mocha

  Array
    #indexOf()
      ✓ should return -1 when the value is not present


  1 passing (9ms)
Set up a test script in package.json:
"scripts": {
  "test": "mocha"
}
Then run tests with:
$ npm test


2) Jasmine -

Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.

Mocha and Jasmine Differences

Assertions
Assertions are boolean functions that are used to test behavior. Typically, a true result indicates that a test passed, indicating that the expected behavior is what occurred when the test ran.
Jasmine includes an assertion library that uses an expect-style syntax:
Mocha does not have a built-in assertion library. Developers must use a dedicated assertion libraryin combination with Mocha. The popular Chai assertion library uses a syntax similar to Jasmine.

Test Doubles / Spies
Test double frameworks create test doubles. A test double, or spy, is like a clone of an object. A test double has the same functions as the original object. However, those functions are “stubbed out,” meaning that they don’t do anything. The “stubbed” functions exist so the test double framework can “watch” the double, tracking the calls to its functions.
Jasmine includes a spyOn method that can be used to create spies:
Once again, Mocha does not include a spy framework. The SinonJS framework is a popular choice for creating spies:






Comments

Popular posts from this blog

What is V8 Engine? What is the relationship between Node.js and V8?