> On 25 Oct 2014, at 13:36, Honza Břečka <[email protected]> wrote:
>
> Hi,
>
> I just want to know how do you unit-test that the following function, part of
> many node packages, returns expected result?
>
> var http = require('http');
> var https = require('https');
>
> function getUrlLoader(url) {
> return url.indexOf('https') ? https : http;
> }
Export it:
module.exports = getUrlLoader;
then try:
var test = require('tape');
var http = require('http');
var https = require('https');
var subject = require('./yourmodule');
test('check it out', function (t) {
t.equal(subject('https') == https);
t.equal(subject('http') == http);
t.end();
});
This exploits the fact that the return value from require is cached and
consistent.
Also, just as a side note, please consider the url.parse method, rather than
doing a naive indexOf on the URL for this purpose.
Aria
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/59F3A4D2-40CB-4701-8B29-CEDBC2FD8259%40nbtsc.org.
For more options, visit https://groups.google.com/d/optout.