-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests: mock fetch in PermissionsCheck tests #3958
Conversation
Branch preview✅ Deploy successful! Storybook: |
ESLint Summary View Full Report
Report generated by eslint-plus-action |
Coverage report
Test suite run success1436 tests passing in 198 suites. Report generated by 🧪jest coverage report action from 63263a3 |
📦 Next.js Bundle Analysis for safe-wallet-webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 🎉 Global Bundle Size Decreased
DetailsThe global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster. Any third party scripts you have added directly to your app using the If you want further insight into what is behind the changes, give @next/bundle-analyzer a try! |
Object.defineProperty(window, 'fetch', { | ||
writable: true, | ||
value: jest.fn(() => | ||
Promise.resolve({ | ||
ok: false, | ||
json: () => Promise.resolve({}), | ||
}), | ||
), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know which call ends up doing the fetch? Imo we shouldn't mock fetch but instead mock our own functions that wrap the fetch calls. It seems we are overwriting the global object, do you know if this is cleaned up after the tests run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the same type of mock in the GasPrice tests and it seems to be fine.
What it solves
The PermissionsCheck tests were doing actual fetch requests to a gas oracle which sometimes failed on CI. Fetch is now mocked to return an empty object.