【问题标题】:Mocha/Jasmine: Using describe and it correctly ? Standard pattern available?摩卡/茉莉花:正确使用描述和它?标准模式可用吗?
【发布时间】:2018-01-13 18:41:27
【问题描述】:

我想知道是否有一些标准模式可以正确使用描述。我正在测试一个节点应用程序,因此我的测试存储在根目录下名为 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 /*

是否推荐使用方法名,理解在计算类中会有多个不同的方法?

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

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

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

【问题讨论】:

    标签: unit-testing jasmine mocha.js jestjs


    【解决方案1】:

    您的 mocha 测试应该如下所示。

    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");
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多