mardi 18 août 2020

Writing basic test case with JEST for infinity condition

Here I have added the test file and implementation ,I am trying to write a test case to check whether the divisor is zero and if it is zero send a message "infinity"

//code in test file  
    describe("valid divisions", () => {
        
          test("3 / 0 = infinity", () => {
          expect(divide(x,y)).toHaveReturnedWith('infinity');
        });
    });
    
    //code in js file
     
    const divide = (x, y) => {
        if (y===0){
         return('infinity');
        }
         else {
          return x / y;
         } 
      };

Aucun commentaire:

Enregistrer un commentaire