1

I am trying to test my contract with Mocha. So far, my solution has been this:

it("transfers token ownership", async () => {
        const tokenInstance = await DappToken.deployed()
        expect(async () => { await tokenInstance.transfer(accounts[1], 9999999999999999999) }).to.throw('user has insufficient funds');
    })

But I get this error: AssertionError: expected [Function] to throw an error

Any idea how to fix? Thanks!

Richard Zhang
  • 71
  • 2
  • 5
  • It *doesn't* throw an error - it's returning a promise, it *rejects*. See e.g. https://stackoverflow.com/q/31845329/3001761. – jonrsharpe Dec 22 '20 at 18:17
  • Doesn't the arrow function given to the expect need to be invoked? `expect()` is not going to invoke a callback given to it. It is expect to be given a value to behave against. At least that is my experience with most jasmine like testing suites. – Taplar Dec 22 '20 at 18:18
  • Try it without the extra arrow function. `expect(await tokenInstance.transfer(accounts[1], 9999999999999999999))`. though that might not address an issue jon is pointing out – Taplar Dec 22 '20 at 18:21

0 Answers0