Mocking JavaScript Requests During Tests
11-Mar-2022 1421
When we run tests, we don’t want to hit external services in most cases, so our tests don’t depend on external services and are more stable. We can use gems like VCR or WebMock to stub the requests that are done by the Rails application, but when the request is initiated by the JavaScript code… that’s a different story.Two Different ApproachesIn both cases we run tests that use the Capybara and Selenium-webdriver gems. This is the default when creating a new Rails application so you should already have them in your Gemfile. The tests can be of type feature, integration, system, etc, because, as long as the type of test uses Selenium and Capybara, we can proxy or intercept the requests.
Mocking JavaScript Requests During Tests #ruby #rubydeveloper #rubyonrails #Mocking #JavaScript #Requests #During #Tests #javascript #tests https://rubyonrails.ba/link/mocking-javascript-requests-during-tests