diff --git a/lib/fill_in_govuk_text_field.rb b/lib/fill_in_govuk_text_field.rb index eea3a50..8720f86 100644 --- a/lib/fill_in_govuk_text_field.rb +++ b/lib/fill_in_govuk_text_field.rb @@ -33,6 +33,7 @@ def fill_in @input = @inputs.first check_associated_element_is_a_form_field + check_input_type_is_text aria_described_by_ids = @input["aria-describedby"].to_s.strip.split(/\s+/) @@ -103,6 +104,10 @@ def check_associated_element_is_a_form_field end end + def check_input_type_is_text + raise "Found the field, but it has type=\"#{@input[:type]}\", expected type=\"text\"" unless @input[:type] == "text" + end + def check_field_is_described_by_a_hint if @described_by_elements.size == 0 check_if_the_hint_exists_but_is_not_associated_with_field diff --git a/spec/fill_in_govuk_text_field_spec.rb b/spec/fill_in_govuk_text_field_spec.rb index ccb4a1f..63e0ba5 100644 --- a/spec/fill_in_govuk_text_field_spec.rb +++ b/spec/fill_in_govuk_text_field_spec.rb @@ -294,5 +294,23 @@ expect(page.find_field("What is the name of the event?").value).to eql("Design System Day") end end + + context "where the input has type=email" do + before do + TestApp.body = '
+ + +
' + visit('/') + end + + it 'should raise an error' do + expect { + fill_in_govuk_text_field("Email address", with: "test@example.com") + }.to raise_error('Found the field, but it has type="email", expected type="text"') + end + end end end