diff options
author | Dan Miller <danjm.com@gmail.com> | 2019-05-08 01:52:02 +0800 |
---|---|---|
committer | Dan Miller <danjm.com@gmail.com> | 2019-05-08 01:57:20 +0800 |
commit | b481497246316c90ab95cf14a393d1f8ae7eeafc (patch) | |
tree | b5f2be5575554e97f06aab13a55b7c22f5491c8f /test | |
parent | 581128503c161bc3b569ca5d87e4eea8b0d15150 (diff) | |
download | tangerine-wallet-browser-b481497246316c90ab95cf14a393d1f8ae7eeafc.tar tangerine-wallet-browser-b481497246316c90ab95cf14a393d1f8ae7eeafc.tar.gz tangerine-wallet-browser-b481497246316c90ab95cf14a393d1f8ae7eeafc.tar.bz2 tangerine-wallet-browser-b481497246316c90ab95cf14a393d1f8ae7eeafc.tar.lz tangerine-wallet-browser-b481497246316c90ab95cf14a393d1f8ae7eeafc.tar.xz tangerine-wallet-browser-b481497246316c90ab95cf14a393d1f8ae7eeafc.tar.zst tangerine-wallet-browser-b481497246316c90ab95cf14a393d1f8ae7eeafc.zip |
Fix fetch and ethquery mocks in integration tests
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/lib/confirm-sig-requests.js | 13 | ||||
-rw-r--r-- | test/integration/lib/currency-localization.js | 11 | ||||
-rw-r--r-- | test/integration/lib/send-new-ui.js | 3 | ||||
-rw-r--r-- | test/integration/lib/tx-list-items.js | 11 |
4 files changed, 31 insertions, 7 deletions
diff --git a/test/integration/lib/confirm-sig-requests.js b/test/integration/lib/confirm-sig-requests.js index c3b0dfcff..4c2b56c21 100644 --- a/test/integration/lib/confirm-sig-requests.js +++ b/test/integration/lib/confirm-sig-requests.js @@ -15,16 +15,25 @@ QUnit.test('successful confirmation of sig requests', (assert) => { }) }) +global.ethQuery = global.ethQuery || {} + async function runConfirmSigRequestsTest (assert, done) { const selectState = await queryAsync($, 'select') selectState.val('confirm sig requests') reactTriggerChange(selectState[0]) + const realFetch = window.fetch.bind(window) global.fetch = (...args) => { - if (args[0].match(/chromeextensionmm/)) { + if (args[0] === 'https://ethgasstation.info/json/ethgasAPI.json') { + return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasBasic)) }) + } else if (args[0] === 'https://ethgasstation.info/json/predictTable.json') { + return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasPredictTable)) }) + } else if (args[0] === 'https://dev.blockscale.net/api/gasexpress.json') { + return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.gasExpress)) }) + } else if (args[0].match(/chromeextensionmm/)) { return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.metametrics)) }) } - return window.fetch(...args) + return realFetch.fetch(...args) } const pendingRequestItem = $.find('.transaction-list-item .transaction-list-item__grid') diff --git a/test/integration/lib/currency-localization.js b/test/integration/lib/currency-localization.js index cd10efa30..36837e059 100644 --- a/test/integration/lib/currency-localization.js +++ b/test/integration/lib/currency-localization.js @@ -21,11 +21,18 @@ async function runCurrencyLocalizationTest (assert, done) { const selectState = await queryAsync($, 'select') selectState.val('currency localization') + const realFetch = window.fetch.bind(window) global.fetch = (...args) => { - if (args[0].match(/chromeextensionmm/)) { + if (args[0] === 'https://ethgasstation.info/json/ethgasAPI.json') { + return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasBasic)) }) + } else if (args[0] === 'https://ethgasstation.info/json/predictTable.json') { + return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasPredictTable)) }) + } else if (args[0] === 'https://dev.blockscale.net/api/gasexpress.json') { + return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.gasExpress)) }) + } else if (args[0].match(/chromeextensionmm/)) { return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.metametrics)) }) } - return window.fetch(...args) + return realFetch.fetch(...args) } await timeout(1000) diff --git a/test/integration/lib/send-new-ui.js b/test/integration/lib/send-new-ui.js index 6a58611d1..85487a59f 100644 --- a/test/integration/lib/send-new-ui.js +++ b/test/integration/lib/send-new-ui.js @@ -25,6 +25,7 @@ global.ethereumProvider = {} async function runSendFlowTest (assert, done) { const tempFetch = global.fetch + const realFetch = window.fetch.bind(window) global.fetch = (...args) => { if (args[0] === 'https://ethgasstation.info/json/ethgasAPI.json') { return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasBasic)) }) @@ -35,7 +36,7 @@ async function runSendFlowTest (assert, done) { } else if (args[0].match(/chromeextensionmm/)) { return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.metametrics)) }) } - return window.fetch(...args) + return realFetch.fetch(...args) } console.log('*** start runSendFlowTest') diff --git a/test/integration/lib/tx-list-items.js b/test/integration/lib/tx-list-items.js index c0056dd22..91645c5c5 100644 --- a/test/integration/lib/tx-list-items.js +++ b/test/integration/lib/tx-list-items.js @@ -26,11 +26,18 @@ async function runTxListItemsTest (assert, done) { selectState.val('tx list items') reactTriggerChange(selectState[0]) + const realFetch = window.fetch.bind(window) global.fetch = (...args) => { - if (args[0].match(/chromeextensionmm/)) { + if (args[0] === 'https://ethgasstation.info/json/ethgasAPI.json') { + return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasBasic)) }) + } else if (args[0] === 'https://ethgasstation.info/json/predictTable.json') { + return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasPredictTable)) }) + } else if (args[0] === 'https://dev.blockscale.net/api/gasexpress.json') { + return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.gasExpress)) }) + } else if (args[0].match(/chromeextensionmm/)) { return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.metametrics)) }) } - return window.fetch(...args) + return realFetch.fetch(...args) } const metamaskLogo = await queryAsync($, '.app-header__logo-container') |