-
-
Save dmikis/6092739 to your computer and use it in GitHub Desktop.
Thought on Node.js modules testing: instead of creating separate file with tests just write test within module. For example, here `b.js` - some module, and `a.js` uses it. If we call `node a.js`, it'll just output `Hello, world` without running assertions in `b.js`. But if we call `node b.js` it'll call assertions as module tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var b = require('./b'); | |
console.log(b.hello('world')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hello = exports.hello = function (v) { | |
return 'Hello, ' + v; | |
}; | |
if (require('path').resolve(process.cwd(), process.argv[1]) === __filename) { | |
console.assert(hello('b') === 'Hello, b', 'hello method doesn\'t work!'); | |
console.assert(hello('b') === 'Goodbye!', 'broken assertion for demonstration'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment