Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Unable to quiet js console.log #94

lucassus opened this Issue · 15 comments

Currently there is no option to quiet javascript console.log calls. Sometimes it leads to pretty noisy tests output:

..........................................................................MOCK GET:

It would be great if there were a tag (in RSpec, for example) we could use to silence console.log output for tests that are expected to generate output. For example, if I'm testing that a particular AJAX call results in a 4xx error, then I don't want to see that error from console.log in the test output every time (though I might want to see the output if the test fails).

What if there were a runtime option like :js_silent (and corresponding RSpec tag) that would suppress console.log as long as the test passes? I can implement it if the idea seems sound.


+1, it sounds good










I don't know much about the internals of Poltergeist or PhantomJS, but a possible implementation would be injecting some JavaScript like this:

(function () {
  var emptyFunction = function () {};

  // List from
  window.console = {
    log: emptyFunction,
    debug: emptyFunction,
    info: emptyFunction,
    warn: emptyFunction,
    error: emptyFunction,
    assert: emptyFunction,
    dir: emptyFunction,
    dirxml: emptyFunction,
    trace: emptyFunction,
    group: emptyFunction,
    groupCollapsed: emptyFunction,
    groupEnd: emptyFunction,
    time: emptyFunction,
    timeEnd: emptyFunction,
    profile: emptyFunction,
    profileEnd: emptyFunction,
    count: emptyFunction

Because JavaScript functions are variadic, emptyFunction will just ignore whatever's passed in.

This works in a pinch now if you're being affected by this issue.




Another solution would be to allow you to set the IO object it was written to. You could output to a log or capture it to test it's contents.


building off of @tjsingleton suggestion: #230


+1 (Also, thanks for poltergeist! :smile:)


Closing this because of merged #230 and phantomjs_logger option.

@route route closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.