Mocking JavaScript Requests During Tests

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 #javascript #tests https://rubyonrails.ba/single/mocking-javascript-requests-during-tests

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles