Javascript class not being loaded on feature tests with Capybara

242 views Asked by At

I have a coffee class which is called in the create.js.coffee file. It works fine on development. However when running feature tests (with Capybara and web-kit), it seems that this class isn't getting loaded properly.

These are the files:

assets/javascript/app_init.js.coffee

window.MyApp = { }

assets/javascript/modules/product_module.js.coffee

window.MyApp.ProductModule = class ProductModule
  @show: ->
    # Do stuff

assets/javascript/application.js

//= require app_init
//= require_tree .

And the create.js.coffee

console.log window.MyApp => Returns [Object Object]
console.log window.MyApp.ProductModule => Returns undefined

These returns are what I get when running the specs and debugging. Any ideas?

I am using Rails 5 if that helps

2

There are 2 answers

0
ascherman On

I run rails assets:precompile and it fixed the tests. I am not sure why I needed to precompile assets to run the test. I might have something wrong at the configuration. Ideas?

0
ascherman On

It seems the test.rb file configuration, doesn't include the assets compile anymore. The solution to this is to add this to test.rb

config.assets.compile = true