Hardik Pithva
Hardik Pithva

Reputation: 1745

Jasmine javaScript exception

I created simple test case in Jasmine for arithmetic operation in which it gives error Expected function to throw an exception. though i already did that.

spec file

describe("Arithmetic Operation",function(){
    it("adds 2 numbers i.e. 5,5",function(){
        expect(doAddition(5,5)).toEqual(10);
    });

    it("throws an error while adding", function () {   
        expect(function () {doAddition(1,2)}).toThrow(new Error("Not allowed."));
    });
});

src file

function doAddition(a,b){
  return parseInt(a) + parseInt(b);
}

It is working fine if i remove exception code. Any suggestion or idea what's wrong in this?

Upvotes: 0

Views: 62

Answers (1)

Madara's Ghost
Madara's Ghost

Reputation: 175088

You expect doAddition(1,2) to throw, it does not. Hence the test fail.

Upvotes: 2

Related Questions