Page 1 of 1

Using console.log in a Node JS test

Posted: Fri Feb 01, 2013 3:50 pm
by mats
Here's some background detailing why you cannot access symbols like 'console' in a Node sandbox.

https://www.hacksparrow.com/scripting-a-node-js-app.html

Here's a hack to work around it if you need access to the console object.

Decorate the Harness with the console object.
Harness.configure({
    title       : 'Cross-platform Test Suite',

    testClass   : testClass,
    console     : console,
    preload     : [
        'preload/preload.js'
    ]
})
And in your test:
StartTest(function(t) {
    t.harness.console.log('foo');

    t.is(1, 1, 'Correct')
})