How can I check that a form field is prefilled correctly using capybara?

后端 未结 5 1405
不知归路
不知归路 2021-01-30 01:48

I have a field with a proper label that I can fill in with capybara without a problem:

fill_in \'Your name\', with: \'John\'

I\'d like to check

5条回答
  •  滥情空心
    2021-01-30 02:34

    I was wondering how to do something slightly different: I wanted to test whether the field had some value (while making use of Capybara's ability to re-test the matcher until it matches). It turns out that it's possible to use a "filter block" to do this:

    expect(page).to have_field("field_name") { |field|
      field.value.present?
    }
    

提交回复
热议问题