Jasmine expect logic (expect A OR B)

后端 未结 4 1648
执念已碎
执念已碎 2020-12-28 12:40

I need to set the test to succeed if one of the two expectations is met:

expect(mySpy.mostRecentCall.args[0]).toEqual(jasmine.any(Number));
expect(mySpy.most         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-28 13:08

    This is an old question, but in case anyone is still looking I have another answer.

    How about building the logical OR expression and just expecting that? Like this:

    var argIsANumber = !isNaN(mySpy.mostRecentCall.args[0]);
    var argIsBooleanFalse = (mySpy.mostRecentCall.args[0] === false);
    
    expect( argIsANumber || argIsBooleanFalse ).toBe(true);
    

    This way, you can explicitly test/expect the OR condition, and you just need to use Jasmine to test for a Boolean match/mismatch. Will work in Jasmine 1 or Jasmine 2 :)

提交回复
热议问题