1

I'm writing a simple NodeJS (Node 9.4.0) server that's using web3 (1 beta) to interact with Ethereum.

I've created a simple utility web3 as follows:

const Web3 = require('web3')

const url = process.env.WEB3_PROVIDER_URL || 'ws://localhost:8546'
const web3 = new Web3(Web3.givenProvider || url)

module.exports = web3

I've written a trivial mocha (4.0) test as follows

const { expect } = require('chai')
const web3 = require('../../../src/utils/web3')

describe('web3', () => {
  it('exists', () => {
    expect(web3).to.exist
  })
})

The test passes fine but mocha never exists unless I add the --exit flag.

How can I close or otherwise cleanup web3 after my test so mocha exists correctly without the use of the --exit flag?

  • I believe you have to use the done() function to finish the "it" test, no? – Florian Castelain Jan 18 '18 at 6:39
  • that's only for asynchronous tests – Dave Sag Jan 18 '18 at 7:21
-1

Does it work like this?

describe('web3', () => {
  it('exists', (done) => {
    if(web3.currentProvider) {
      web3.currentProvider.reset() // or something...
    }
    done();
  })
})

The code above is untested, but you may get the idea.

Your Answer

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

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