Open
Description
This is a tracking issue for improving unit tests in various ways.
Related issues:
- Mock endpoints during tests #1
- Use Jest for stubbing modules rather than Sinon #744
- Update test setup to reset and restore all mocks between each test #745
- Minimize use of setup/teardown hooks (e.g.
before
,beforeEach
,after
,afterEach
) #746 - Ensure all test assertions/matchers are executed during the test, before it ends #748
- Ensure all async operations are completed before tests end #493
- Don't test private functions #749
- Don't stub prototypes #750
- Minimize the use of
/* istanbul ignore */
comments #743
Some general advice: writing unit tests should be easy. They may be verbose and time consuming to write, but they should be easy. If it's not easy, change the API under test to make it easy.
Many of the APIs in this repository make unit testing difficult. Your time is better spent improving the API first and writing simple unit tests, rather than struggling to write complex tests for a complex API. Consider ways to reduce the API surface, reduce dependencies, inject dependencies to simplify stubbing, and move complex functionality into separate modules.
Tracker by module:
Check off each module as they are audited for each of the criteria outlined above.
- ./src/announcement/AnnouncementController.test.ts
- ./src/permissions/Caveat.test.ts
- ./src/permissions/PermissionController.test.ts
- ./src/permissions/rpc-methods/requestPermissions.test.ts
- ./src/permissions/rpc-methods/getPermissions.test.ts
- ./src/permissions/errors.test.ts
- ./src/permissions/Permission.test.ts
- ./src/keyring/KeyringController.test.ts
- ./src/notification/NotificationController.test.ts
- ./src/third-party/EnsController.test.ts
- ./src/third-party/PhishingController.test.ts
- ./src/BaseControllerV2.test.ts
- ./src/message-manager/MessageManager.test.ts
- ./src/message-manager/AbstractMessageManager.test.ts
- ./src/message-manager/PersonalMessageManager.test.ts
- ./src/message-manager/TypedMessageManager.test.ts
- ./src/assets/AccountTrackerController.test.ts
- ./src/assets/AssetsContractController.test.ts
- ./src/assets/NftController.test.ts
- ./src/assets/assetsUtil.test.ts
- ./src/assets/CurrencyRateController.test.ts
- ./src/assets/TokenBalancesController.test.ts
- ./src/assets/TokenListController.test.ts
- ./src/assets/TokenDetectionController.test.ts
- ./src/assets/NftDetectionController.test.ts
- ./src/assets/TokensController.test.ts
- ./src/assets/TokenRatesController.test.ts
- ./src/assets/Standards/NftStandards/ERC721/ERC721Standard.test.ts
- ./src/assets/Standards/NftStandards/ERC1155/ERC1155Standard.test.ts
- ./src/assets/Standards/ERC20Standard.test.ts
- ./src/user/AddressBookController.test.ts
- ./src/user/PreferencesController.test.ts
- ./src/subject-metadata/SubjectMetadataController.test.ts
- ./src/network/NetworkController.test.ts
- ./src/ControllerMessenger.test.ts
- ./src/ratelimit/RateLimitController.test.ts
- ./src/gas/fetchGasEstimatesViaEthFeeHistory.test.ts
- ./src/gas/fetchGasEstimatesViaEthFeeHistory/calculateGasFeeEstimatesForPriorityLevels.test.ts
- ./src/gas/gas-util.test.ts
- ./src/gas/determineGasFeeCalculations.test.ts
- ./src/gas/fetchBlockFeeHistory.test.ts
- ./src/gas/GasFeeController.test.ts
- ./src/BaseController.test.ts
- ./src/ComposableController.test.ts
- ./src/transaction/TransactionController.test.ts
- ./src/util.test.ts
- ./src/apis/crypto-compare.test.ts
- ./src/apis/token-service.test.ts
- ./src/approval/ApprovalController.test.ts