1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Network controller nock

This commit is contained in:
Thomas Huang 2018-02-15 09:54:22 -08:00
parent 33182efb13
commit 8f7094a73d

View File

@ -2,28 +2,37 @@ const assert = require('assert')
const nock = require('nock')
const NetworkController = require('../../app/scripts/controllers/network')
const { createTestProviderTools } = require('../stub/provider')
const providerResultStub = {}
const provider = createTestProviderTools({ scaffold: providerResultStub }).provider
describe('# Network Controller', function () {
let networkController
const noop = () => {}
const networkControllerProviderInit = {
getAccounts: () => {},
}
beforeEach(function () {
nock('https://api.infura.io')
.get('/*/')
.reply(200, {})
.reply(200)
nock('https://rinkeby.infura.io')
.post('/metamask')
.reply(200)
networkController = new NetworkController({
provider: {
type: 'rinkeby',
},
provider,
})
networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor)
networkController.initializeProvider(networkControllerProviderInit, provider)
})
describe('network', function () {
describe('#provider', function () {
it('provider should be updatable without reassignment', function () {
networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor)
networkController.initializeProvider(networkControllerProviderInit, provider)
const proxy = networkController._proxy
proxy.setTarget({ test: true, on: () => {} })
assert.ok(proxy.test)
@ -68,21 +77,4 @@ describe('# Network Controller', function () {
})
})
})
})
function dummyProviderConstructor() {
return {
// provider
sendAsync: noop,
// block tracker
_blockTracker: {},
start: noop,
stop: noop,
on: noop,
addListener: noop,
once: noop,
removeAllListeners: noop,
}
}
function noop() {}
})