简体   繁体   中英

Why js from a file in tests does not work?

I have a small test to check the appearance of an select by pressing the checkbox.

The js code is in a separate file. If start the server and check manually, everything works.

I also include this file in application.js

But in the test this file is not connected.

If I insert js code directly into the html code, then everything works again.

My js file:

$(document).on('ready', function() {
  $('#checkme').on('change', function(e) {
    if ($(this).is(':checked')) {
      $('#interval').css('display', 'block');
    } else {
      $('#interval').css('display', 'none');
    }
  })
});

My test:

assert_not page.has_select?(:interval) #true
page.check('Checkme')                 #true
page.save_and_open_screenshot(full: true) #screenshot
assert page.has_select?(:interval) #false

In the screenshot I received, I see that the checkbox is active, but js does not work.

This was due to precompile assets. I deleted the public/assets folder, where I had old compiled js files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM