摩卡/茉莉花:正确使用描述和它?提供标准模式?



我想知道是否有一些标准模式能够正确使用描述和它。我正在测试一个节点应用程序,因此我的测试存储在根目录中名为 tests 的目录下。

我试图理解如何使用描述。我的第一个想法是使用类名和方法名作为描述,然后对使用它的方法进行不同的测试情况。我想是这样的。

describe ('Calculation Class')
describe ('getSquaredArea()')
it('should return correct value if passed a valid numeric')
/* one situation */
it('should return null when the value passed is not a numeric) 
/* another situation /*

是否建议使用方法名称,了解在计算类中将有许多不同的方法?

我想我的问题指的是摩卡或茉莉花或开玩笑。

我也在考虑测试前端,我正在考虑使用上面的相同模式,但删除第一个描述,因为测试将与它们正在测试的文件一起存储,而不是单独存储在测试根目录中。

我不确定上面的第二个描述,只是在那里播放方法名称。

你的摩卡测试应该是这样的。

var testObj;
describe ('#User', function () {
beforeEach(function () {
//init what the object contains
testObj = new DataStore(data, Container);
});
describe ('Admin', function () {
//other tests
});
it ('#Should return the name of the user', function () {
assert.equal(testObj.get('user'), dummyData.user);
});
it("should offer simple HTTP request capabilities", function () {
return chakram.get("http://httpbin.org/get");
});
});

最新更新