What's a good way to reuse test code using Jasmine?

前端 未结 8 626
無奈伤痛
無奈伤痛 2020-12-05 07:01

I\'m using the Jasmine BDD Javascript library and really enjoying it. I have test code that I\'d like to reuse (for example, testing multiple implementations of a base clas

8条回答
  •  孤城傲影
    2020-12-05 07:51

    Here is a simpler solution. Declare a variable function and use it, without using the this keyword or context:

    describe("Test Suit", function ()
    {
       var TestCommonFunction = function(inputObjects)
       {
         //common code here or return objects and functions here etc
       };
    
       it("Should do x and y", function()
       {
           //Prepare someInputObjects
           TestCommonFunction(someInputObjects);
           //do the rest of the test or evaluation
       });
    });
    

    You can also return an object with more functions and call the returned functions thereafter.

提交回复
热议问题