2

I am testing at the moment some smart contracts with truffle(mocha/chai/chai-as-promised) and have the following problem:

I have a getter, and this getter delivers an UINT value, then when I try to test the value with the instance.getMemberCount().should.eventually.equal(4) the result is: expected { Object (s, e, ...) } to equal 4.

Interesting fact is that when I try to compare the values directly with ‘==’ there is no problem.. (for example: assert.equal(instance.getMemberCount() == 4))

Has Mocha/Chai problems transforming the uint values?

3
  • getMemberCount().toNumber() ? maybe Commented Aug 11, 2017 at 3:55
  • @ВиталийШвецов - there is no toNumber() in JavaScript or I am wrong? I have tried with Number(), parseInt() - but the result is NaN, because we have 'object Promise' and I am still stuck ..
    – val3ri
    Commented Aug 11, 2017 at 7:23
  • 1
    @val3ri Web3 has a BigNumber object which has a toNumber. ethereumbuilders.gitbooks.io/guide/content/en/… see "web3.toBigNumber"
    – ABCD.ca
    Commented Jun 30, 2018 at 21:30

1 Answer 1

2

You can use .valueOf() to get the return value from the getter function.

I've used this in one of the test cases I wrote sometime back.

You can take a look at this for reference.

Hope this helps.

1
  • Thanks for the github repository link I will search for answers there! With .valueOf() the result is: [object Promise]. And after printing the result is: { [String: '4'] s: 1, e: 0, c: [ 4 ] }. JavaScript is converting somehow this object and the comparison with "==" works.
    – val3ri
    Commented Aug 14, 2017 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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