Skip to content

Commit

Permalink
fix: DRYing jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juanky201271 committed Mar 4, 2025
1 parent 49d3de4 commit 201ce0b
Show file tree
Hide file tree
Showing 28 changed files with 30 additions and 387 deletions.
16 changes: 16 additions & 0 deletions __mocks__/react-native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};
RN.View = jest.fn();

return RN;
});
16 changes: 0 additions & 16 deletions __tests__/AddressBook.AbDetail.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ import { AddressBookActionEnum, AddressBookFileClass } from '../app/AppState';
import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockAddressBook } from '../__mocks__/dataMocks/mockAddressBook';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component Address Book Details - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/AddressBook.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@ import { AddressBook } from '../components/AddressBook';
import { mockAddressBook } from '../__mocks__/dataMocks/mockAddressBook';
import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component Address Book - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/App.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@ import React from 'react';
import { render } from '@testing-library/react-native';
import App from '../App';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component App - test', () => {
//snapshot test
Expand Down
4 changes: 2 additions & 2 deletions __tests__/DetailLine.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';

import { render } from '@testing-library/react-native';
import DetailLine from '../components/Components/DetailLine';
import { View } from 'react-native';
import RegText from '../components/Components/RegText';

// test suite
describe('Component DetailLine - test', () => {
Expand All @@ -17,7 +17,7 @@ describe('Component DetailLine - test', () => {
expect(detail.toJSON()).toMatchSnapshot();
});
test('DetailLine children - snapshot', () => {
const children = <View />;
const children = <RegText>{'Hello'}</RegText>;
const detail = render(<DetailLine label="label" children={children} />);
expect(detail.toJSON()).toMatchSnapshot();
});
Expand Down
1 change: 0 additions & 1 deletion __tests__/Header.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockInfo } from '../__mocks__/dataMocks/mockInfo';
import { mockTotalBalance } from '../__mocks__/dataMocks/mockTotalBalance';


// test suite
describe('Component Header - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/History.ValueTransferDetail.unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@ import { mockInfo } from '../__mocks__/dataMocks/mockInfo';
import { mockTotalBalance } from '../__mocks__/dataMocks/mockTotalBalance';
import { mockValueTransfers } from '../__mocks__/dataMocks/mockValueTransfers';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component History ValueTransferDetail - test', () => {
//unit test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/History.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@ import { mockTotalBalance } from '../__mocks__/dataMocks/mockTotalBalance';
import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockAddresses } from '../__mocks__/dataMocks/mockAddresses';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component History - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/ImportUfvk.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockInfo } from '../__mocks__/dataMocks/mockInfo';
import { mockTotalBalance } from '../__mocks__/dataMocks/mockTotalBalance';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component ImportUfvk - test', () => {
//snapshot test
Expand Down
15 changes: 0 additions & 15 deletions __tests__/Info.es.unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@ jest.mock('react-native-localize', () => ({
};
},
}));
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component Info - test', () => {
Expand Down
16 changes: 0 additions & 16 deletions __tests__/Info.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@ import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockTotalBalance } from '../__mocks__/dataMocks/mockTotalBalance';
import { mockZecPrice } from '../__mocks__/dataMocks/mockZecPrice';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component Info - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/Info.us.unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ import { CurrencyEnum } from '../app/AppState';
import { mockInfo } from '../__mocks__/dataMocks/mockInfo';
import { mockZecPrice } from '../__mocks__/dataMocks/mockZecPrice';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component Info - test', () => {
//unit test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/Insight.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockInfo } from '../__mocks__/dataMocks/mockInfo';
import { mockTotalBalance } from '../__mocks__/dataMocks/mockTotalBalance';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component Insight - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/LoadedApp.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ import { mockBackground } from '../__mocks__/dataMocks/mockBackground';
import { mockSecurity } from '../__mocks__/dataMocks/mockSecurity';
import { mockAddressBook } from '../__mocks__/dataMocks/mockAddressBook';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component LoadedApp - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/LoadingApp.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ import { mockServer } from '../__mocks__/dataMocks/mockServer';
import { mockBackground } from '../__mocks__/dataMocks/mockBackground';
import { mockSecurity } from '../__mocks__/dataMocks/mockSecurity';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component LoadingApp - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/Memo.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@ import Memo from '../components/Memo';
import { defaultAppContextLoaded, ContextAppLoadedProvider } from '../app/context';
import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component Memo - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/Messages.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@ import { mockTotalBalance } from '../__mocks__/dataMocks/mockTotalBalance';
import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockAddresses } from '../__mocks__/dataMocks/mockAddresses';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component Messages - test', () => {
//snapshot test
Expand Down
16 changes: 0 additions & 16 deletions __tests__/MessagesAddress.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@ import { mockTotalBalance } from '../__mocks__/dataMocks/mockTotalBalance';
import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockAddresses } from '../__mocks__/dataMocks/mockAddresses';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};

return RN;
});

// test suite
describe('Component Messages Address - test', () => {
//snapshot test
Expand Down
Loading

0 comments on commit 201ce0b

Please sign in to comment.