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
Importing other .js files in Buster.js tests
-
30-06-2022 - |
Question
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?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow