Note that there are some explanatory texts on larger screens.

plurals
  1. POlearning nodeunit
    text
    copied!<p>I trying to bend my head around the async nature of node.js and nodeunit.</p> <p>now nodeunit is supposed to help me out but it gives me headaches as well:</p> <pre><code>$ nodeunit test_logfile.js test_logfile.js ✖ testLogentry Error: Expected 1 assertions, 0 ran at Object.done (/home/mark/.node_libraries/.npm/nodeunit/0.5.1/package/lib/types.js:119:25) at /home/mark/devel/PerfDriver/test/test_logfile.js:48:10 at Object.runTest (/home/mark/.node_libraries/.npm/nodeunit/0.5.1/package/lib/core.js:54:9) at /home/mark/.node_libraries/.npm/nodeunit/0.5.1/package/lib/core.js:90:21 at /home/mark/.node_libraries/.npm/nodeunit/0.5.1/package/deps/async.js:508:13 at /home/mark/.node_libraries/.npm/nodeunit/0.5.1/package/deps/async.js:118:13 at /home/mark/.node_libraries/.npm/nodeunit/0.5.1/package/deps/async.js:134:9 at /home/mark/.node_libraries/.npm/nodeunit/0.5.1/package/deps/async.js:507:9 at Object.concatSeries (/home/mark/.node_libraries/.npm/nodeunit/0.5.1/package/deps/async.js:147:23) at Object.runSuite (/home/mark/.node_libraries/.npm/nodeunit/0.5.1/package/lib/core.js:79:11) FAILURES: 1/1 assertions failed (50ms) node.js:116 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: ECONNREFUSED, Connection refused at Socket._onConnect (net.js:576:18) at IOWatcher.onWritable [as callback] (net.js:165:12) </code></pre> <p>here is my testcase:</p> <pre><code>var nodeunit = require('../lib/nodeunit/lib/nodeunit.js') var http = require('http'); var logfile = require('../src/logfile.js'); var testmsg = 'this is my first testmessage:-_,.:;öüäß?1234"@€'; exports.testLogentry = function(test) { test.expect(1); // make sure all the async expectations are fulfilled var options = { host: 'localhost', port: 8123, path: '/', method: 'POST', record_message: function(msg) { console.log('received ' + msg + '\n'); test.equal(msg, testmsg); return; } }; var logger = logfile.loggerFactory(options); logfile.write(testmsg, options); logger.stop(); test.done(); }; </code></pre> <p>I guess my question is if assertions work well in callbacks or if there are any restrictions that might cause the testcase to fail. My assumption is that nodeunit is able to cope with the asynchronous programming style. So I expect "test.equal(msg, testmsg);" to work. If I run the content of the testcase in the node console then "record_message" is called. I would post logfile.js as well but this is probably to much and I am looking for more general advice.</p> <p>Thanks.</p> <p>Mark</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload