Testing jQuery input mask in RSpec

Noah Clark

I'm trying to test a jQuery input mask using an rspec feature test.

The mask looks like:

$(function() {
  $('.format-date').inputmask('99/99/9999',{ 'placeholder': 'mm/dd/yyyy' }); 
})

And the feature test looks like

feature 'create a thing', type: :feature, js: true do
  scenario 'submit a new thing' do
    given_a_logged_in_admin
    visit '/thing/new'
    fill_in 'Effective Date', with: '11112020'

    click_button 'Submit'

I would expect the input mask to convert this to 11/11/2020. It doesn't appear to be doing that and additionally, I would like to make sure the page contains 11/11/2020 as well.

It works in the browser so it must be something to do with the test.

Noah Clark

@jvillian sent me down the right path. I was trying to inspect the element and see if the input values had changed. I'm not sure why that didn't work, but if you google around trying to solve this problem you'll see people doing that to write their tests. However, when I tried to write a failing test instead of verify that the values had changed, I was able to write a test that works with jQuery input mask in rspec.

page.should have_field("object_effective_date", with: "11/11/2020")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related