Giter Site home page Giter Site logo

sinon-ng's Introduction

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

sinon-ng's People

Contributors

boneskull avatar

Stargazers

Ganaraj P R avatar Robert McBride avatar Colin Ewen avatar Eugene Datsky avatar André Gil avatar Patrick Dahms avatar Daniel Stern avatar

Watchers

Richard Hess avatar James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.