Skip to content

Instantly share code, notes, and snippets.

@benwillkommen
Created May 9, 2016 19:54
Show Gist options
  • Save benwillkommen/92ce116b96801c95af070199ba8ab4ad to your computer and use it in GitHub Desktop.
Save benwillkommen/92ce116b96801c95af070199ba8ab4ad to your computer and use it in GitHub Desktop.
mocking w/ sinon example
//weird codewars function
function _if(bool, func1, func2) {
if(bool === true){
return func1();
} else {
return func2();
}
};
//arrange
var function1 = function(){console.log("asdf")};
var function2 = function(){console.log("jkl;")};
var spy1 = sinon.spy(function1);
var spy2 = sinon.spy(function2);
//act
_if(true, function1, function2);
//assert
Test.assertTrue(spy1.calledOnce);
Test.assertFalse(spy2.called);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment