UNPKG

eventric-testing

Version:
99 lines (89 loc) 2.22 kB
var FakePromise, _isPromise, slice = [].slice; _isPromise = function(promise) { return promise && typeof promise.then === 'function' && typeof promise["catch"] === 'function'; }; FakePromise = (function() { function FakePromise() {} FakePromise.prototype.resolve = function() { var args; args = 1 <= arguments.length ? slice.call(arguments, 0) : []; return { then: function(callback) { var promise; if (callback == null) { callback = function() {}; } promise = callback.apply(this, args); if (_isPromise(promise)) { return promise; } else { return this; } }, "catch": function() { return this; } }; }; FakePromise.prototype.reject = function() { var args; args = 1 <= arguments.length ? slice.call(arguments, 0) : []; return { then: function() { return this; }, "catch": function(callback) { var promise; if (callback == null) { callback = function() {}; } promise = callback.apply(this, args); if (_isPromise(promise)) { promise; } else { this; } return this; } }; }; FakePromise.prototype.resolveAsync = function() { var args; args = 1 <= arguments.length ? slice.call(arguments, 0) : []; return { then: function(callback) { if (callback == null) { callback = function() {}; } setTimeout(function() { return callback.apply(this, args); }, 0); return this; }, "catch": function() { return this; } }; }; FakePromise.prototype.rejectAsync = function() { var args; args = 1 <= arguments.length ? slice.call(arguments, 0) : []; return { then: function() { return this; }, "catch": function(callback) { if (callback == null) { callback = function() {}; } setTimeout(function() { return callback.apply(this, args); }, 0); return this; } }; }; return FakePromise; })(); module.exports = new FakePromise;