DEV Community

Omar White
Omar White

Posted on

How do you test code that uses browser api's?

I've been working with the Web Payment Request API recently and have found that its kind of a pain to test my code. The solution i've come to is writing wrapper functions for the browser API calls and mocking those in my tests. This allows me to isolate the browser API code and test around it, but i'm wondering if there is a better way. I would appreciate any insights.

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay