Skip to content

Commit

Permalink
Add doc comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kumabook committed Jan 22, 2017
1 parent 48824bc commit 8ffcfbb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/call.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @class
*/
var Call = function(params) {
this.args = params.args;
this.calledAt = params.calledAt;
Expand Down
35 changes: 33 additions & 2 deletions src/expectation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ var ResultType = {
RESOLVE: 2,
REJECT: 3
};

/**
* @class
*/
var Expectation = function() {
this.hasArgs = false;
this.args = [];
Expand All @@ -15,40 +17,69 @@ var Expectation = function() {
this.resolvedValue = null;
this.rejectedReason = null;
this.callbacks = [];
this.isFulfilled = false;
this.resultType = ResultType.RETURN;
/**
* bool value if the expectation is fulfilled or not
* @instance
* @type {bool}
*/
this.isFulfilled = false;
};

/**
* Add condition about arguments
* @return {Expectation}
*/
Expectation.prototype.withArgs = function() {
this.hasArgs = true;
this.args = Array.prototype.slice.call(arguments);
return this;
};

/**
* Expects the function returns specified value
* @return {Expectation}
*/
Expectation.prototype.returns = function(value) {
this.returnValue = value;
this.resultType = ResultType.RETURN;
return this;
};

/**
* Expects the function throws specified error
* @return {Expectation}
*/
Expectation.prototype.throws = function(error) {
this.thrownError = error;
this.resultType = ResultType.THROW;
return this;
};

/**
* Expects the function returns a promise object that resolves specified value
* @return {Expectation}
*/
Expectation.prototype.resolves = function(value) {
this.resolvedValue = value;
this.resultType = ResultType.RESOLVE;
return this;
};

/**
* Expects the function returns a promise object that rejects specified value
* @return {Expectation}
*/
Expectation.prototype.rejects = function(reason) {
this.rejectedReason = reason;
this.resultType = ResultType.REJECT;
return this;
};

/**
* Expects the function calls specified function
* @return {Expectation}
*/
Expectation.prototype.calls = function(func, thisArg) {
var args = Array.prototype.slice.call(arguments, 2);
this.callbacks.push({
Expand Down
5 changes: 5 additions & 0 deletions src/expects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
var Expectation = require('./expectation');

/**
* Create a new expectation of the function or method
* @function expects
* @return {Expectation}
*/
module.exports = function(func) {
var expectation = new Expectation();
func.expectations.push(expectation);
Expand Down
11 changes: 11 additions & 0 deletions src/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ var isFunc = util.isFunc;
var contains = util.contains;
var keys = util.keys;

/**
* Create a fake object.
* The fake object has cloned properties and cloned methods or fake methods:
* - The methods in `except` options are copied to the fake object from original object.
* - The methods in `only` options are fake functions.
* - As default, All methods are fake functions.
* @param {Object} object a fake object
* @param {string[]?} opts.except method name list. the methods of a object are not fake function, use original method.
* @param {string[]?} opts.only method name list. The methods of a object are fake function instead of original method.
* @return {Object} a fake object
*/
var obj = function(object, opts) {
var key;
var fake = {};
Expand Down
16 changes: 15 additions & 1 deletion src/promise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
var Promise = global.Promise;

module.exports = {
/**
* @namespace promise
*/
var promise = {
/**
* Return current Promise constructor
*/
constructor: function() {
return Promise;
},
/**
* Use the specified Promise constructor instead
*/
use: function(constructor) {
Promise = constructor;
},
/**
* Use default Promise
*/
restoreDefault: function() {
Promise = global.Promise;
}
};

module.exports = promise;

0 comments on commit 8ffcfbb

Please sign in to comment.