Using console.log in a Node JS test

Get help with testing, discuss unit testing strategies etc.
Post Reply
User avatar
mats
Core Developer
Core Developer
Posts: 14554
Joined: Sat Dec 19, 2009 11:41 pm
Location: Sweden
Contact:

Using console.log in a Node JS test

Post by mats » Fri Feb 01, 2013 3:50 pm

Here's some background detailing why you cannot access symbols like 'console' in a Node sandbox.

http://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.

Code: Select all

Harness.configure({
    title       : 'Cross-platform Test Suite',

    testClass   : testClass,
    console     : console,
    preload     : [
        'preload/preload.js'
    ]
})
And in your test:

Code: Select all

StartTest(function(t) {
    t.harness.console.log('foo');

    t.is(1, 1, 'Correct')
})    
Tired of debugging javascript errors in web applications? Try our new error logging service RootCause, or read more on the Sencha blog

@bryntum
Facebook
API documentation

Post Reply