test-example
v0.4.3
Published
A JSDoc plugin for generating test files by parsing @example
Downloads
40
Maintainers
Readme
Test Example
A JSDoc plugin for generating test files by parsing @example.
Feature
BDD (Behavior-driven development) style Test wrapper, such as Mocha
Should style Assertion
One Source file to one Test file
One Doclet to one
describe()
One
@example
to oneit()
//
also supports multiple-line code with the example result
Usage
npm i test-example -D
Add some config options
Custom hook module let you do more
jsdoc -c path/to/config.json
npm test
Example
source/say-sth.js
/**
* Hello function
*
* @function hello
*
* @param {string} [name="World"]
*
* @return {string}
*
* @example // No parameter
*
* hello() // "Hello, World !"
*
* @example // One parameter
*
* hello('JSDoc') // "Hello, JSDoc !"
*/
exports.hello = function (name) {
return 'Hello, ' + (name || 'World') + ' !';
};
will generate test/say-sth.js
'use strict';
require('should');
var saySth = require('../source/say-sth');
describe('hello', function () {
it('No parameter', function () {
var result = saySth.hello();
result.should.be.deepEqual( "Hello, World !" );
});
it('One parameter', function () {
var result = saySth.hello('JSDoc');
result.should.be.deepEqual( "Hello, JSDoc !" );
});
});
[ Remark ] A blank line is necessary between the title & code of @example
.