Reputation: 3561
I have the following file in javascript:
function myLocalHouse() {
this.buyHouse(money, date) {
//code I want to test with mocha
};
};
I want to test the buyHouse
method.
I have tried the most easy thing in the world, but as hard as I try It doesn't work
var myLocalHouseInstance = require('/myLocalHouse.js');
suite('houses suite', function() {
test('test that buy House works correctly', function() {
var something = myLocalHouseInstance.buyHouse(100, '17/08/2013');
});
});
Unfortunately this doesn't work, when I execute mocha
it says method buyHouse
is undefined.
I execute the test with:
mocha -u tdd
Thanks
Upvotes: 2
Views: 437
Reputation: 66
You need to export your function in myLocalHouse.js. Try something like this:
exports.myLocalHouse = function() {
this.buyHouse = function(money, date) {
}
}
or
function myLocalHouse() {
this.buyHouse = function(money, date) {
}
}
exports.myLocalHouse = myLocalHouse;
then in your test
var myLocalHouse = require('./myLocalHouse.js').myLocalHouse;
suite('houses suite', function() {
test('test that buy House works correctly', function() {
var myLocalHouseInstance = new myLocalHouse();
var something = myLocalHouseInstance.buyHouse(100, '17/08/2013');
});
});
Upvotes: 2