From 8f7094a73d4ca5879e8290e3b1aefdc42397767d Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Thu, 15 Feb 2018 09:54:22 -0800 Subject: [PATCH] Network controller nock --- test/unit/network-contoller-test.js | 40 ++++++++++++----------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/test/unit/network-contoller-test.js b/test/unit/network-contoller-test.js index fe3b9e66a..cd8c345c5 100644 --- a/test/unit/network-contoller-test.js +++ b/test/unit/network-contoller-test.js @@ -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() {} \ No newline at end of file +}) \ No newline at end of file