3 ms·
Shamless plug: Fed up with there not being a dead simple library for stubbing stuff when writing Javascript tests in Jasmine (I come from the Ruby world), I wro
by lucaspiller 13y ago
Shamless plug: Fed up with there not being a dead simple library for stubbing stuff when writing Javascript tests in Jasmine (I come from the Ruby world), I wrote Why.js. It let's you stub anything and everything, and is optimised for tests written in Coffeescript.
Example:
why.stub 'User.find', (userId) ->
{ name: 'Bob' }
https://github.com/lucaspiller/why.js https://github.com/lucaspiller/why.js
- tieTYT 13y agoWhy (no pun intended) should I use this over sinon?
- lucaspiller 13y agoI should probably add that to the readme: I was using Sinon for other stuff (mainly the spies to check stuff is called), and wanted to mock a call to X.Y.Z. This was an external component with it's own tests, so for test isolation it wasn't included in the environment for this test - as such X.Y and X.Y.Z didn't exist. Sinon has the mock function, but you can't call it on stuff that doesn't exist. I guess you could stub X to include Y then stub that to include Z but it seems a bit overkill. Also coming from a Ruby background I'm not a fan of Sinon's quite verbose syntax. So I quickly whipped this up to do what I wanted :)