Skip to content

Instantly share code, notes, and snippets.

@marknadig
Created September 1, 2015 16:25
Show Gist options
  • Save marknadig/c3e8f2d3fff9d22da42b to your computer and use it in GitHub Desktop.
Save marknadig/c3e8f2d3fff9d22da42b to your computer and use it in GitHub Desktop.
An angular promise mock
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