Last active
June 20, 2016 17:18
-
-
Save carlows/34a9895f06bd251caa03cca18b548f40 to your computer and use it in GitHub Desktop.
Mock example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
// funcion proveniente de alguna libreria | |
// realiza un call http (aca lo simulamos con un timeout) | |
function executeHttpCall(message) { | |
setTimeout(function () {}, 1000); | |
} | |
// nuestra funcion, la que nos interesa probar | |
function myFunction(http, message, value) { | |
if(value > 20) { | |
executeHttpCall(message); | |
} | |
} | |
function mock(message) { | |
return true; | |
} | |
// acá es como la llamamos normalmente | |
myFunction(executeHttpCall, "Hola mundo", 42); | |
// acá es como la llamamos en nuestras pruebas | |
// tenemos control total ya que el mock nos pertenece | |
myFunction(mock, "Hola mundo", 42); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment