Skip to content

Commit

Permalink
[DDW-1091] Check mocked function call count
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Araujo committed May 2, 2022
1 parent 549a875 commit 266d2b9
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions source/renderer/app/components/wallet/WalletSendForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,26 @@ describe('wallet/Wallet Send Form', () => {
}

function createTransactionFeeMock(times: number, minimumAda: number) {
const mock = jest.fn().mockResolvedValue({
fee: new BigNumber(1),
minimumAda: new BigNumber(1),
const mock = jest.fn().mockImplementation(() => {
// eslint-disable-next-line no-console
console.log('Default call');

return Promise.resolve({
fee: new BigNumber(1),
minimumAda: new BigNumber(1),
});
});
Array.from({
length: times,
}).forEach(() => {
// @ts-ignore
mock.mockResolvedValueOnce({
fee: new BigNumber(1),
minimumAda: new BigNumber(minimumAda),
}).forEach((_, index) => {
mock.mockImplementationOnce(() => {
// eslint-disable-next-line no-console
console.log(`Call ${index + 1}`);

return Promise.resolve({
fee: new BigNumber(1),
minimumAda: new BigNumber(minimumAda),
});
});
});
return mock;
Expand Down Expand Up @@ -374,7 +383,8 @@ describe('wallet/Wallet Send Form', () => {
expect(adaInput).toHaveValue(`${minimumAda},000000`);
});

test('should calculate transaction fee even when one of the assets are empty', async () => {
// eslint-disable-next-line
test.only('should calculate transaction fee even when one of the assets are empty', async () => {
expect.assertions(2);
const minimumAda = 2;
const calculateTransactionFeeMock = createTransactionFeeMock(4, minimumAda);
Expand All @@ -383,10 +393,25 @@ describe('wallet/Wallet Send Form', () => {
);
enterReceiverAddress();
await addToken(0);
// eslint-disable-next-line no-console
console.log(
'calculateTransactionFeeMock call count:',
calculateTransactionFeeMock.mock.calls.length
);
await waitForMinimumAdaRequiredMsg(1);
expect(getInput('Ada')).toHaveValue('');
await addToken(minimumAda, 1);
// eslint-disable-next-line no-console
console.log(
'calculateTransactionFeeMock call count:',
calculateTransactionFeeMock.mock.calls.length
);
await waitForMinimumAdaRequiredMsg();
// eslint-disable-next-line no-console
console.log(
'calculateTransactionFeeMock call count:',
calculateTransactionFeeMock.mock.calls.length
);
assertAdaInput(minimumAda);
});

Expand Down

0 comments on commit 266d2b9

Please sign in to comment.