mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Await completion of async actions under test (#8386)
Some of the unit tests for `actions.js` were calling async actions without `await`-ing them. All async actions are now called with `await` to ensure they've completed.
This commit is contained in:
parent
d68f156ac7
commit
1eaffee00d
@ -277,23 +277,23 @@ describe('Actions', function () {
|
|||||||
describe('#addNewKeyring', function () {
|
describe('#addNewKeyring', function () {
|
||||||
let addNewKeyringSpy
|
let addNewKeyringSpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
addNewKeyringSpy = sinon.stub(background, 'addNewKeyring')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
addNewKeyringSpy.restore()
|
addNewKeyringSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls addNewKeyring', function () {
|
it('calls addNewKeyring', async function () {
|
||||||
|
addNewKeyringSpy = sinon.stub(background, 'addNewKeyring')
|
||||||
|
.callsArgWith(2, null)
|
||||||
const privateKey = 'c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3'
|
const privateKey = 'c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3'
|
||||||
|
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
store.dispatch(actions.addNewKeyring('Simple Key Pair', [ privateKey ]))
|
await store.dispatch(actions.addNewKeyring('Simple Key Pair', [ privateKey ]))
|
||||||
assert(addNewKeyringSpy.calledOnce)
|
assert(addNewKeyringSpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('errors then addNewKeyring in background throws', function () {
|
it('errors then addNewKeyring in background throws', async function () {
|
||||||
|
addNewKeyringSpy = sinon.stub(background, 'addNewKeyring')
|
||||||
|
.callsArgWith(2, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
@ -301,11 +301,7 @@ describe('Actions', function () {
|
|||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
|
|
||||||
addNewKeyringSpy.callsFake((_, __, callback) => {
|
await store.dispatch(actions.addNewKeyring())
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
store.dispatch(actions.addNewKeyring())
|
|
||||||
assert.deepEqual(store.getActions(), expectedActions)
|
assert.deepEqual(store.getActions(), expectedActions)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -367,14 +363,14 @@ describe('Actions', function () {
|
|||||||
importAccountWithStrategySpy.restore()
|
importAccountWithStrategySpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls importAccountWithStrategies in background', function () {
|
it('calls importAccountWithStrategies in background', async function () {
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
importAccountWithStrategySpy = sinon.spy(background, 'importAccountWithStrategy')
|
importAccountWithStrategySpy = sinon.spy(background, 'importAccountWithStrategy')
|
||||||
|
|
||||||
const importPrivkey = 'c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3'
|
const importPrivkey = 'c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3'
|
||||||
|
|
||||||
store.dispatch(actions.importNewAccount('Private Key', [ importPrivkey ]))
|
await store.dispatch(actions.importNewAccount('Private Key', [ importPrivkey ]))
|
||||||
assert(importAccountWithStrategySpy.calledOnce)
|
assert(importAccountWithStrategySpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -403,12 +399,12 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
describe('#addNewAccount', function () {
|
describe('#addNewAccount', function () {
|
||||||
|
|
||||||
it('Adds a new account', function () {
|
it('Adds a new account', async function () {
|
||||||
const store = mockStore({ metamask: devState })
|
const store = mockStore({ metamask: devState })
|
||||||
|
|
||||||
const addNewAccountSpy = sinon.spy(background, 'addNewAccount')
|
const addNewAccountSpy = sinon.spy(background, 'addNewAccount')
|
||||||
|
|
||||||
store.dispatch(actions.addNewAccount())
|
await store.dispatch(actions.addNewAccount())
|
||||||
assert(addNewAccountSpy.calledOnce)
|
assert(addNewAccountSpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -418,23 +414,22 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
let checkHardwareStatusSpy
|
let checkHardwareStatusSpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
checkHardwareStatusSpy = sinon.stub(background, 'checkHardwareStatus')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
checkHardwareStatusSpy.restore()
|
checkHardwareStatusSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls checkHardwareStatus in background', async function () {
|
it('calls checkHardwareStatus in background', async function () {
|
||||||
|
checkHardwareStatusSpy = sinon.stub(background, 'checkHardwareStatus')
|
||||||
|
.callsArgWith(2, null)
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
store.dispatch(await actions.checkHardwareStatus('ledger', `m/44'/60'/0'/0`))
|
await store.dispatch(actions.checkHardwareStatus('ledger', `m/44'/60'/0'/0`))
|
||||||
assert.equal(checkHardwareStatusSpy.calledOnce, true)
|
assert.equal(checkHardwareStatusSpy.calledOnce, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows loading indicator and displays error', async function () {
|
it('shows loading indicator and displays error', async function () {
|
||||||
|
checkHardwareStatusSpy = sinon.stub(background, 'checkHardwareStatus')
|
||||||
|
.callsArgWith(2, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
@ -442,10 +437,6 @@ describe('Actions', function () {
|
|||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
|
|
||||||
checkHardwareStatusSpy.callsFake((_, __, callback) => {
|
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await store.dispatch(actions.checkHardwareStatus())
|
await store.dispatch(actions.checkHardwareStatus())
|
||||||
assert.fail('Should have thrown error')
|
assert.fail('Should have thrown error')
|
||||||
@ -459,24 +450,23 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
let forgetDeviceSpy
|
let forgetDeviceSpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
forgetDeviceSpy = sinon.stub(background, 'forgetDevice')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
forgetDeviceSpy.restore()
|
forgetDeviceSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls forgetDevice in background', function () {
|
it('calls forgetDevice in background', async function () {
|
||||||
|
forgetDeviceSpy = sinon.stub(background, 'forgetDevice')
|
||||||
|
.callsArgWith(1, null)
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
store.dispatch(actions.forgetDevice('ledger'))
|
await store.dispatch(actions.forgetDevice('ledger'))
|
||||||
assert.equal(forgetDeviceSpy.calledOnce, true)
|
assert.equal(forgetDeviceSpy.calledOnce, true)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows loading indicator and displays error', async function () {
|
it('shows loading indicator and displays error', async function () {
|
||||||
|
forgetDeviceSpy = sinon.stub(background, 'forgetDevice')
|
||||||
|
.callsArgWith(1, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
@ -484,10 +474,6 @@ describe('Actions', function () {
|
|||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
|
|
||||||
forgetDeviceSpy.callsFake((_, callback) => {
|
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await store.dispatch(actions.forgetDevice())
|
await store.dispatch(actions.forgetDevice())
|
||||||
assert.fail('Should have thrown error')
|
assert.fail('Should have thrown error')
|
||||||
@ -501,24 +487,23 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
let connectHardwareSpy
|
let connectHardwareSpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
connectHardwareSpy = sinon.stub(background, 'connectHardware')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
connectHardwareSpy.restore()
|
connectHardwareSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls connectHardware in background', function () {
|
it('calls connectHardware in background', async function () {
|
||||||
|
connectHardwareSpy = sinon.stub(background, 'connectHardware')
|
||||||
|
.callsArgWith(3, null)
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
store.dispatch(actions.connectHardware('ledger', 0, `m/44'/60'/0'/0`))
|
await store.dispatch(actions.connectHardware('ledger', 0, `m/44'/60'/0'/0`))
|
||||||
assert.equal(connectHardwareSpy.calledOnce, true)
|
assert.equal(connectHardwareSpy.calledOnce, true)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows loading indicator and displays error', async function () {
|
it('shows loading indicator and displays error', async function () {
|
||||||
|
connectHardwareSpy = sinon.stub(background, 'connectHardware')
|
||||||
|
.callsArgWith(3, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
@ -526,10 +511,6 @@ describe('Actions', function () {
|
|||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
|
|
||||||
connectHardwareSpy.callsFake((_, __, ___, callback) => {
|
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await store.dispatch(actions.connectHardware())
|
await store.dispatch(actions.connectHardware())
|
||||||
assert.fail('Should have thrown error')
|
assert.fail('Should have thrown error')
|
||||||
@ -543,24 +524,23 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
let unlockHardwareWalletAccountSpy
|
let unlockHardwareWalletAccountSpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
unlockHardwareWalletAccountSpy = sinon.stub(background, 'unlockHardwareWalletAccount')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
unlockHardwareWalletAccountSpy.restore()
|
unlockHardwareWalletAccountSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls unlockHardwareWalletAccount in background', function () {
|
it('calls unlockHardwareWalletAccount in background', async function () {
|
||||||
|
unlockHardwareWalletAccountSpy = sinon.stub(background, 'unlockHardwareWalletAccount')
|
||||||
|
.callsArgWith(3, null)
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
store.dispatch(actions.unlockHardwareWalletAccount('ledger', 0, `m/44'/60'/0'/0`))
|
await store.dispatch(actions.unlockHardwareWalletAccount('ledger', 0, `m/44'/60'/0'/0`))
|
||||||
assert.equal(unlockHardwareWalletAccountSpy.calledOnce, true)
|
assert.equal(unlockHardwareWalletAccountSpy.calledOnce, true)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows loading indicator and displays error', async function () {
|
it('shows loading indicator and displays error', async function () {
|
||||||
|
unlockHardwareWalletAccountSpy = sinon.stub(background, 'unlockHardwareWalletAccount')
|
||||||
|
.callsArgWith(3, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
@ -568,10 +548,6 @@ describe('Actions', function () {
|
|||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
|
|
||||||
unlockHardwareWalletAccountSpy.callsFake((_, __, ___, callback) => {
|
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await store.dispatch(actions.unlockHardwareWalletAccount())
|
await store.dispatch(actions.unlockHardwareWalletAccount())
|
||||||
assert.fail('Should have thrown error')
|
assert.fail('Should have thrown error')
|
||||||
@ -585,33 +561,30 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
let setCurrentCurrencySpy
|
let setCurrentCurrencySpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
setCurrentCurrencySpy = sinon.stub(background, 'setCurrentCurrency')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
setCurrentCurrencySpy.restore()
|
setCurrentCurrencySpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls setCurrentCurrency', function () {
|
it('calls setCurrentCurrency', async function () {
|
||||||
|
setCurrentCurrencySpy = sinon.stub(background, 'setCurrentCurrency')
|
||||||
|
.callsArgWith(1, null, {})
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
store.dispatch(actions.setCurrentCurrency('jpy'))
|
await store.dispatch(actions.setCurrentCurrency('jpy'))
|
||||||
assert(setCurrentCurrencySpy.calledOnce)
|
assert(setCurrentCurrencySpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws if setCurrentCurrency throws', function () {
|
it('throws if setCurrentCurrency throws', async function () {
|
||||||
|
setCurrentCurrencySpy = sinon.stub(background, 'setCurrentCurrency')
|
||||||
|
.callsArgWith(1, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
{ type: 'HIDE_LOADING_INDICATION' },
|
{ type: 'HIDE_LOADING_INDICATION' },
|
||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
setCurrentCurrencySpy.callsFake((_, callback) => {
|
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
store.dispatch(actions.setCurrentCurrency())
|
await store.dispatch(actions.setCurrentCurrency())
|
||||||
assert.deepEqual(store.getActions(), expectedActions)
|
assert.deepEqual(store.getActions(), expectedActions)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -637,13 +610,13 @@ describe('Actions', function () {
|
|||||||
signMessageSpy.restore()
|
signMessageSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls signMsg in background', function () {
|
it('calls signMsg in background', async function () {
|
||||||
const store = mockStore({
|
const store = mockStore({
|
||||||
metamask: {},
|
metamask: {},
|
||||||
})
|
})
|
||||||
|
|
||||||
signMessageSpy = sinon.spy(background, 'signMessage')
|
signMessageSpy = sinon.spy(background, 'signMessage')
|
||||||
store.dispatch(actions.signMsg(msgParams))
|
await store.dispatch(actions.signMsg(msgParams))
|
||||||
assert(signMessageSpy.calledOnce)
|
assert(signMessageSpy.calledOnce)
|
||||||
|
|
||||||
})
|
})
|
||||||
@ -695,14 +668,14 @@ describe('Actions', function () {
|
|||||||
signPersonalMessageSpy.restore()
|
signPersonalMessageSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls signPersonalMessage', function () {
|
it('calls signPersonalMessage', async function () {
|
||||||
const store = mockStore({
|
const store = mockStore({
|
||||||
metamask: {},
|
metamask: {},
|
||||||
})
|
})
|
||||||
|
|
||||||
signPersonalMessageSpy = sinon.spy(background, 'signPersonalMessage')
|
signPersonalMessageSpy = sinon.spy(background, 'signPersonalMessage')
|
||||||
|
|
||||||
store.dispatch(actions.signPersonalMsg(msgParams))
|
await store.dispatch(actions.signPersonalMsg(msgParams))
|
||||||
assert(signPersonalMessageSpy.calledOnce)
|
assert(signPersonalMessageSpy.calledOnce)
|
||||||
|
|
||||||
})
|
})
|
||||||
@ -780,22 +753,25 @@ describe('Actions', function () {
|
|||||||
typedMessages = metamaskController.typedMessageManager.messages
|
typedMessages = metamaskController.typedMessageManager.messages
|
||||||
msgId = Object.keys(messages)[0]
|
msgId = Object.keys(messages)[0]
|
||||||
typedMessages[0].msgParams.metamaskId = parseInt(msgId)
|
typedMessages[0].msgParams.metamaskId = parseInt(msgId)
|
||||||
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
signTypedMsgSpy.restore()
|
signTypedMsgSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls signTypedMsg in background with no error', function () {
|
it('calls signTypedMsg in background with no error', async function () {
|
||||||
const store = mockStore()
|
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
|
||||||
|
.callsArgWith(1, null, devState)
|
||||||
|
const store = mockStore({ metamask: devState })
|
||||||
|
|
||||||
store.dispatch(actions.signTypedMsg(msgParamsV3))
|
await store.dispatch(actions.signTypedMsg(msgParamsV3))
|
||||||
assert(signTypedMsgSpy.calledOnce)
|
assert(signTypedMsgSpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns expected actions with error', async function () {
|
it('returns expected actions with error', async function () {
|
||||||
const store = mockStore()
|
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
|
||||||
|
.callsArgWith(1, new Error('error'))
|
||||||
|
const store = mockStore({ metamask: devState })
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
{ type: 'UPDATE_METAMASK_STATE', value: undefined },
|
{ type: 'UPDATE_METAMASK_STATE', value: undefined },
|
||||||
@ -803,10 +779,6 @@ describe('Actions', function () {
|
|||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
|
|
||||||
signTypedMsgSpy.callsFake((_, callback) => {
|
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await store.dispatch(actions.signTypedMsg())
|
await store.dispatch(actions.signTypedMsg())
|
||||||
assert.fail('Should have thrown error')
|
assert.fail('Should have thrown error')
|
||||||
@ -1080,22 +1052,22 @@ describe('Actions', function () {
|
|||||||
describe('#addToken', function () {
|
describe('#addToken', function () {
|
||||||
let addTokenSpy
|
let addTokenSpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
addTokenSpy = sinon.stub(background, 'addToken')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
addTokenSpy.restore()
|
addTokenSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls addToken in background', async function () {
|
it('calls addToken in background', async function () {
|
||||||
|
addTokenSpy = sinon.stub(background, 'addToken')
|
||||||
|
.callsArgWith(4, null)
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
store.dispatch(actions.addToken())
|
await store.dispatch(actions.addToken())
|
||||||
assert(addTokenSpy.calledOnce)
|
assert(addTokenSpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('errors when addToken in background throws', async function () {
|
it('errors when addToken in background throws', async function () {
|
||||||
|
addTokenSpy = sinon.stub(background, 'addToken')
|
||||||
|
.callsArgWith(4, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
@ -1103,10 +1075,6 @@ describe('Actions', function () {
|
|||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
|
|
||||||
addTokenSpy.callsFake((_, __, ___, ____, callback) => {
|
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await store.dispatch(actions.addToken())
|
await store.dispatch(actions.addToken())
|
||||||
assert.fail('Should have thrown error')
|
assert.fail('Should have thrown error')
|
||||||
@ -1120,21 +1088,21 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
let removeTokenSpy
|
let removeTokenSpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
removeTokenSpy = sinon.stub(background, 'removeToken')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
removeTokenSpy.restore()
|
removeTokenSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls removeToken in background', async function () {
|
it('calls removeToken in background', async function () {
|
||||||
|
removeTokenSpy = sinon.stub(background, 'removeToken')
|
||||||
|
.callsArgWith(1, null)
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
store.dispatch(await actions.removeToken())
|
await store.dispatch(actions.removeToken())
|
||||||
assert(removeTokenSpy.calledOnce)
|
assert(removeTokenSpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('errors when removeToken in background fails', async function () {
|
it('errors when removeToken in background fails', async function () {
|
||||||
|
removeTokenSpy = sinon.stub(background, 'removeToken')
|
||||||
|
.callsArgWith(1, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
@ -1142,10 +1110,6 @@ describe('Actions', function () {
|
|||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
|
|
||||||
removeTokenSpy.callsFake((_, callback) => {
|
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await store.dispatch(actions.removeToken())
|
await store.dispatch(actions.removeToken())
|
||||||
assert.fail('Should have thrown error')
|
assert.fail('Should have thrown error')
|
||||||
@ -1299,10 +1263,11 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('#setAccountLabel', function () {
|
describe('#setAccountLabel', function () {
|
||||||
it('calls setAccountLabel', function () {
|
it('calls setAccountLabel', async function () {
|
||||||
const setAccountLabelSpy = sinon.stub(background, 'setAccountLabel')
|
const setAccountLabelSpy = sinon.stub(background, 'setAccountLabel')
|
||||||
|
.callsArgWith(2, null)
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
store.dispatch(actions.setAccountLabel('0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', 'test'))
|
await store.dispatch(actions.setAccountLabel('0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', 'test'))
|
||||||
assert(setAccountLabelSpy.calledOnce)
|
assert(setAccountLabelSpy.calledOnce)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -1310,22 +1275,22 @@ describe('Actions', function () {
|
|||||||
describe('#setFeatureFlag', function () {
|
describe('#setFeatureFlag', function () {
|
||||||
let setFeatureFlagSpy
|
let setFeatureFlagSpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
setFeatureFlagSpy = sinon.stub(background, 'setFeatureFlag')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
setFeatureFlagSpy.restore()
|
setFeatureFlagSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls setFeatureFlag in the background', function () {
|
it('calls setFeatureFlag in the background', async function () {
|
||||||
|
setFeatureFlagSpy = sinon.stub(background, 'setFeatureFlag')
|
||||||
|
.callsArgWith(2, null)
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
store.dispatch(actions.setFeatureFlag())
|
await store.dispatch(actions.setFeatureFlag())
|
||||||
assert(setFeatureFlagSpy.calledOnce)
|
assert(setFeatureFlagSpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('errors when setFeatureFlag in background throws', async function () {
|
it('errors when setFeatureFlag in background throws', async function () {
|
||||||
|
setFeatureFlagSpy = sinon.stub(background, 'setFeatureFlag')
|
||||||
|
.callsArgWith(2, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
@ -1333,10 +1298,6 @@ describe('Actions', function () {
|
|||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||||
]
|
]
|
||||||
|
|
||||||
setFeatureFlagSpy.callsFake((_, __, callback) => {
|
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await store.dispatch(actions.setFeatureFlag())
|
await store.dispatch(actions.setFeatureFlag())
|
||||||
assert.fail('Should have thrown error')
|
assert.fail('Should have thrown error')
|
||||||
@ -1364,11 +1325,11 @@ describe('Actions', function () {
|
|||||||
getTransactionCountSpy.restore()
|
getTransactionCountSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls getTransactionCount', function () {
|
it('calls getTransactionCount', async function () {
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
getTransactionCountSpy = sinon.spy(global.ethQuery, 'getTransactionCount')
|
getTransactionCountSpy = sinon.spy(global.ethQuery, 'getTransactionCount')
|
||||||
|
|
||||||
store.dispatch(actions.updateNetworkNonce())
|
await store.dispatch(actions.updateNetworkNonce())
|
||||||
assert(getTransactionCountSpy.calledOnce)
|
assert(getTransactionCountSpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user