Setting Up Javascript Unit-Test
Explore how to set up JavaScript unit testing in Rails applications by configuring Webpack and using tools like Karma, Jasmine, and TestDouble. Understand how to manage dependencies with Yarn and create an effective testing environment including browser integration and handling of source maps.
We'll cover the following...
Webpack configuration
This is going to be a bit involved, unfortunately. Rails 5.1 or later uses the Webpacker gem, which allows us to bypass the Rails asset pipeline and use Webpack, which is an asset-bundling tool commonly used by JavaScript developers. Webpack allows us to do all the same things the old Rails asset pipeline does: module lookup, compilation, conversion to a single minified file, and so on. But Webpack is more integrated with current JavaScript tools and makes it much easier to integrate with JavaScript code that is distributed using the Node Package Manager (NPM).
That’s good news. The less-good news is that Webpack configuration can be really complicated, especially for a Rails developer who is used to convention over configuration. The Rails team has put a lot of effort into ...