Are there any best pratices for testing object oriented javascript in Node.js?
Like for example if I had the following Cat.js class:
function Cat(age, name) {
    this.name = name || null;
    this.age = age || null;
}
Cat.prototype.getAge = function() {
    return this.age;
}
Cat.prototype.setAge = function(age) {
    this.age = age;
}
Cat.prototype.getName = function(name) {
    return this.name;
}
Cat.prototype.setName = function(name) {
    this.name = name;
}
Cat.prototype.equals = function(otherCat) {
    return otherCat.getName() === this.getName()
        && otherCat.getAge() === this.getAge();
}
Cat.prototype.fill = function(newFields) {
    for (var field in newFields) {
        if (this.hasOwnProperty(field) && newFields.hasOwnProperty(field)) {
            if (this[field] !== 'undefined') {
                this[field] = newFields[field];
            }
        }
    }
};
module.exports = Cat;
and I wanted to write test classes that look something like the following like Java's junit tests:
var cat1;
setUp() {
    cat1 = new Cat(10, 'Tom');
}
                Yes, there are a number of them. Answering which is the most popular and/or best is not possible. But two common libraries are Jasmine and Mocha
http://jasmine.github.io/
http://visionmedia.github.io/mocha/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With