是否有类似Junit for Javascript的框架来测试Node.js中的面向对象Javascript?
在Node.js中测试面向对象javascript有什么最佳实践吗 例如,如果我有以下Cat.js类:是否有类似Junit for Javascript的框架来测试Node.js中的面向对象Javascript?,javascript,node.js,oop,unit-testing,testing,Javascript,Node.js,Oop,Unit Testing,Testing,在Node.js中测试面向对象javascript有什么最佳实践吗 例如,如果我有以下Cat.js类: 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
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;
我想编写类似于Java的junit测试的测试类:
var cat1;
setUp() {
cat1 = new Cat(10, 'Tom');
}
是的,有很多。回答哪一个最受欢迎和/或最好是不可能的。但两个常见的图书馆是茉莉花和摩卡咖啡
只是一个提示,这一个可能会被标记为关闭,因为它的范围太广(并要求外部资源建议)。如果可以的话,试着改进一下。有很多。我写了一个名为的小JS库,它既有一个面向对象的框架,也有一个单元测试框架。还有一个JSUnit。现在我还要把Jest添加到列表中)Jest也在那里