sinon-ng

0.1.3 • Public • Published

sinon-ng

AngularJS plugin for Sinon.JS.

Not much here at the moment, but if you don't care to setup mocks for $http calls, this is for you.

API

These examples leverage Mocha, Chai, and Chai as Promised.

fulfills()

Causes a SinonJS stub to return a $q promise, fulfilled with the value you specify. Compatible with the onCall() functions.

Example:

it('should not worry and be happy', inject(function($http) {
  var foo = {
      bar: function() {
        return $http.post('somewhere', {stuff: 'things'});
      }
    }, 
    res = {data: 'other stuff'};
    
  sinon.stub(foo, 'bar').fulfills(res);
  
  return expect(foo.bar()).to.eventually.equal(res);
}));

rejects()

Causes a SinonJS stub to return a $q promise, rejected with the value you specify. Compatible with the onCall() functions.

Example:

it('should go soak its head', inject(function($http) {
  var foo = {
      bar: function() {
        return $http.post('somewhere', {stuff: 'things'});
      }
    }, 
    res = {error: 'oh noes'};
    
  sinon.stub(foo, 'bar').rejects(res);
  
  return expect(foo.bar()).to.eventually.be.rejectedWith(res);
}));

Install

bower install sinon-ng

License

MIT

Author

Christopher Hiller

Readme

Keywords

none

Package Sidebar

Install

npm i sinon-ng

Weekly Downloads

1

Version

0.1.3

License

MIT

Last publish

Collaborators

  • boneskull