sinon promise util
parent
623b562192
commit
f90cde8928
|
@ -60,19 +60,15 @@ describe "UserService", ->
|
|||
{id: 3, name: "fake3"}
|
||||
])
|
||||
|
||||
mocks.resources.users.getContacts = (userId) ->
|
||||
expect(userId).to.be.equal(userId)
|
||||
|
||||
return $q (resolve, reject) ->
|
||||
resolve(contacts)
|
||||
mocks.resources.users.getContacts = sinon.stub().promise()
|
||||
mocks.resources.users.getContacts.withArgs(userId).resolve(contacts)
|
||||
|
||||
userService.attachUserContactsToProjects(userId, projects).then (_projects_) ->
|
||||
contacts = _projects_.get(0).get("contacts")
|
||||
|
||||
expect(contacts.get(0).get("name")).to.be.equal('fake1')
|
||||
done()
|
||||
|
||||
$rootScope.$apply()
|
||||
done()
|
||||
|
||||
it "get user contacts", (done) ->
|
||||
userId = 2
|
||||
|
@ -83,11 +79,8 @@ describe "UserService", ->
|
|||
{id: 3}
|
||||
]
|
||||
|
||||
mocks.resources.users.getContacts = (userId) ->
|
||||
expect(userId).to.be.equal(userId)
|
||||
|
||||
return $q (resolve, reject) ->
|
||||
resolve(contacts)
|
||||
mocks.resources.users.getContacts = sinon.stub().promise()
|
||||
mocks.resources.users.getContacts.withArgs(userId).resolve(contacts)
|
||||
|
||||
userService.getContacts(userId).then (_contacts_) ->
|
||||
expect(_contacts_).to.be.eql(contacts)
|
||||
|
|
|
@ -18,6 +18,8 @@ module.exports = function(config) {
|
|||
'karma.app.conf.js',
|
||||
'dist/js/libs.js',
|
||||
'node_modules/angular-mocks/angular-mocks.js',
|
||||
'node_modules/bluebird/js/browser/bluebird.js',
|
||||
'test-utils.js',
|
||||
'dist/js/app.js',
|
||||
'dist/js/templates.js',
|
||||
'app/**/*spec.coffee'
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
(function() {
|
||||
var searchOriginal = function(obj) {
|
||||
if (obj._promise) {
|
||||
return obj;
|
||||
} else {
|
||||
return searchOriginal(obj.parent);
|
||||
}
|
||||
};
|
||||
|
||||
sinon.stub.promise = function() {
|
||||
var obj = this;
|
||||
|
||||
var returnedPromise = new Promise(function(_resolve_, _reject_){
|
||||
obj._resolvefn = _resolve_;
|
||||
obj._rejectfn = _reject_;
|
||||
});
|
||||
|
||||
this.returns(returnedPromise);
|
||||
this._promise = true;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
sinon.stub.resolve = function() {
|
||||
var original = searchOriginal(this);
|
||||
original._resolvefn.apply(this, arguments);
|
||||
};
|
||||
|
||||
sinon.stub.reject = function() {
|
||||
var original = searchOriginal(this);
|
||||
original._rejectfn.apply(this, arguments);
|
||||
};
|
||||
}());
|
Loading…
Reference in New Issue