Szybka pomoc

Ściągawka z Vows.js

Szybki przewodnik po asynchronicznym frameworku testowym BDD Vows.js dla Node.js: partie (batches), tematy (topics), asercje i wywołania zwrotne.

· Opublikowano

Vows to asynchroniczny framework testowy BDD (Behavior-Driven Development) dla Node.js.

Podstawowe użycie

const vows = require('vows');
const assert = require('assert');

vows
  .describe('Math operations')
  .addBatch({
    'when calculating numbers': {
      topic: function () {
        return 100;
      },
      'should equal 100': function (number) {
        assert.equal(number, 100);
      }
    }
  })
  .export(module);

Uruchamianie testów

vows test/*-test.js --spec

Asercje

assert.equal(a, b);
assert.notEqual(a, b);
assert.strictEqual(a, b);

assert.isNaN(number);
assert.instanceOf(object, klass);
assert.isUndefined(object);
assert.isFunction(func);
assert.isNull(object);
assert.isNotZero(object);
assert.isObject(object);
assert.isString(object);

Asynchroniczne tematy (Topics)

.addBatch({
  'when performing async tasks': {
    topic: function () {
      doAsyncWork(this.callback);
    },
    'should handle callback result': function (err, result) {
      assert.isNull(err);
      assert.equal(result, 42);
    }
  }
})

Powiązane tematy