Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there framework like Junit for Javascript to test object oriented javascript in Node.js? [closed]

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');
}
like image 270
Wang-Zhao-Liu Q Avatar asked Mar 25 '14 17:03

Wang-Zhao-Liu Q


1 Answers

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/

like image 142
Matt Pileggi Avatar answered Sep 20 '22 18:09

Matt Pileggi