Created
September 1, 2015 16:25
-
-
Save marknadig/c3e8f2d3fff9d22da42b to your computer and use it in GitHub Desktop.
An angular promise mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myMocks = { | |
promise: function() { | |
return { | |
_success: [], | |
_failure: [], | |
then: function (_success, _failure) { | |
this._success.push(_success); | |
this._failure.push(_failure); | |
return this; | |
}, | |
// allow tests to resolve promise chain | |
keep: function(ret) { | |
for (var i = 0; i < this._success.length; i++) { | |
ret = this._success[i].call(this, ret) | |
} | |
return ret; | |
}, | |
break: function(ret) { | |
for (var i = 0; i < this._failure.length; i++) { | |
ret = this._failure[i].call(this, ret) | |
} | |
return ret; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment