I am new to asking questions here and I am sorry if my question is not correctly asked!

I am currently testing some smart contracts with truffle and have some problems with testing for exceptions. At the beginning I have used only mocha and chai, but I found chai-as-promised and I thought the tests are going to be more readable after extending them with chai-as-promised. In my case I have implemented the method:

function testForThrow(error) {   return error.toString().indexOf("out of gas") != -1 || error.toString().indexOf("invalid opcode") != -1; }

because the possible error messages are two – “out of gas” or “invalid opcode”. And one test look like this:

}).catch(function(error) {
      assert(testForThrow(error), "expecting throw");

So my problem: chai- as-promised provides the function rejectedWith() but with this function we can test only one possible output, and I can’t come up with solution, because there is no OR in mocha and chai..

Current state of the test declaration with chai-as-promised:

.should.be.rejectedWith("invalid opcode");

Have someone idea how can I do this or the first version is the only possible way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.