MetaMask / MetaMask/metamask-mobile

Chore: mock properly in test setup; ideally without xhr2

Open
#10,390 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3k
Forks
1.7k
Avg merge
1d 14h
Merged PRs (30d)
669

Description

## Description
The current setup in app/store/sagas/xmlHttpRequestOverride.ts test uses 'xhr2' for mocking XMLHttpRequest, which is not ideal for our testing environment. xhr2 is used as XMLHttpRequest is not available in unit test as it runs on node.js and not in RN environment.
Using xhr2 here is making the production code have test specific code. This should be avoided as it makes the testing and coverage unrelated to the real production code and only tests the test specific code.

## Expected Outcome
The test setup should be refactored to mock dependencies without relying on 'xhr2'.

## Steps to Reproduce
1. Run the test suite.
2. Observe the use of 'xhr2' in the network request mocking.

## Expectations

- No use of xhr2.
- No test specific code in the code under test.

## Suggested Implementation
Investigate and integrate an alternative mocking library or approach that is compatible with both React Native and unit test context.

Contributor guide

Open the contributing guide

Research direction

Start by reading app/store/sagas/xmlHttpRequestOverride.ts and the related test setup to understand where xhr2 is introduced and how XMLHttpRequest is mocked in Node.js. Investigate a mocking approach compatible with React Native and unit tests. Done means xhr2 is removed, production code has no test-specific path, and the network-request tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
testing-qa
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.