Skip to content

Instantly share code, notes, and snippets.

@jsilvestre
Last active August 29, 2015 14:14
Show Gist options
  • Save jsilvestre/f62391c20230b74404eb to your computer and use it in GitHub Desktop.
Save jsilvestre/f62391c20230b74404eb to your computer and use it in GitHub Desktop.
Mocking singleton without class
# If I mock markBroken, it's not used in stopApp because the mock wraps module.exports.markBroken but doesn't change the function itself
markBroken = module.exports.markBroken = (app, err) ->
# does something
module.exports.stopApp = (app) ->
manager = new AppManager
manager.stop app, (err, result) ->
return markBroken app, err if err
# I must do that in order to mock markBroken
module.exports.markBroken = (app, err) ->
# does something
module.exports.stopApp = (app) ->
manager = new AppManager
manager.stop app, (err, result) ->
return module.exports.markBroken app, err if err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment