简体   繁体   中英

RSpec/Capybara check not triggering onChange event

I'm testing my JavaScript with RSpec and Capybara with Webkit driver . After I check a checkbox, JS onChange event validates the form and disables submit button untill I check second checkbox.

Here's my test:

it "disables submit button when wrong number of players", js: true do
  visit '/matches/new'
  check 'match_player_ids_1'
  expect(page).to have_button('Create Match', disabled: true)
end

I tried using sleep 2 after checking the checkbox, used binding.pry to check if the element is being checked (it is) but the submit button is still disabled.

Any ideas? Can it be triggered manually?

您可以使用page.execute_script手动进行操作

page.execute_script("$('#match_player_ids_1').trigger('change')")

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