Search code examples
ruby-on-railscapybaraformbuilderpoltergeist

Form Builder is not rendered via Capybara spec


I have a Rails app which is using formBuilder. When I visit the page manually on my browser in which I render my form with the formBuilder, it works just fine. But visiting the page via Capybara spec & Poltergeist, the formBuilder is not rendered.

I have form-builder.min.js and form-render.min.js both version 2.2.5.

Capybara 2.15.4

Poltergeist 1.9.0


Solution

  • The most likely issues for JS not being executed as expected when using Poltergeist, is either an error in some JS being compiled by the asset pipeline, or the use of > ES5 features in a JS file being compiled into the asset pipeline.

    PhantomJS (which Poltergeist depends on) doesn't support anything greater than ES5 so ALL JS must be transpiled and polyfilled to run on an ES5 "browser". Since Rails concatenates the JS files together in test mode, an error or use of ES6 features in any of your JS assets can cause PhantomJS to stop processing later files being included. If you enable js_errors in your Poltergeist config you may see errors reported, however there is a bug in PhantomJS that may silently just stop processing the JS with some ES6 features (let, const, etc - https://github.com/teampoltergeist/poltergeist/issues/823) so just because you don't see errors reported doesn't mean there is no issue in the JS.