1

I'm making my first attempt at Javascript testing, with Buster.js

I've followed the instructions at the Buster site to run "states the obvious" test. However, I haven't been able to import any of my existing .js files into the tests.

For instance, I have a file js/testLibrary.js, containing:

function addTwo(inp) {
  return inp+2;
}

and a file test/first-test.js, containing:

// Node.js tests
var buster = require("buster");
var testLibrary = require("../js/testLibrary.js");
var assert = buster.referee.assert;

buster.testCase("A module", {
    "Test The Library": function() {
            result = addTwo(3);
            console.log(result);
            assert(true, 'a message for you');
    }
});

Running buster-test gives:

Error: A module Test The Library
    ReferenceError: addTwo is not defined
    [...]

Replacing result = addTwo(3); with result = testLibrary.addTwo(3); gives:

Error: A module Test The Library
    TypeError: Object #<Object> has no method 'addTwo'
    [...]

I'm probably missing something really basic, but at present, I'm completely stumped. Can someone point me in the right direction?

scubbo
  • 4,969
  • 7
  • 40
  • 71

1 Answers1

2

That is because you are not exporting this function from the module. Take a look at that: http://nodejs.org/api/modules.html#modules_module_exports

PGJ
  • 126
  • 4
  • Perfect, that did it! I guess it probably shows that I've never used Node.js before, either :) thank you! – scubbo Oct 13 '13 at 12:55