0
}).then(assert.fail).catch (function(error){
      assert(error.message.indexOf('revert') >= 0,'msg.value must be less than tokens tokenAvaliable')
    })

I have the following code in the test file can anyone explain what is indexOf('revert') means

2
  • 3
    I'm voting to close this question as it's not related to Ethereum. indexOf is a JavaScript function: w3schools.com/jsref/jsref_indexof.asp Oct 9 '18 at 6:22
  • What’s the question exactly? What is indexOf or why it’s looking for “revert”?
    – ivicaa
    Oct 9 '18 at 6:35
1

This is because assert.fail() throws an error, which is caught in the catch, and in the error message is the string Expected revert not received, which contains the substring revert.

In JavaScript console try the following:

console.log("Expected revert not received".indexOf('revert'))

You will get an answer 9.

Hope it helps!

Not the answer you're looking for? Browse other questions tagged or ask your own question.