Skip to content

Instantly share code, notes, and snippets.

@carlows
Last active June 20, 2016 17:18
Show Gist options
  • Save carlows/34a9895f06bd251caa03cca18b548f40 to your computer and use it in GitHub Desktop.
Save carlows/34a9895f06bd251caa03cca18b548f40 to your computer and use it in GitHub Desktop.
Mock example
(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