{"record":{"id":"45145de166c4283e","repo":"teamcapybara/capybara","slug":"type-is-not-a-valid-type-for-a-text-query","errorCode":null,"errorMessage":"#{@type} is not a valid type for a text query","messagePattern":"#(.+?) is not a valid type for a text query","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/capybara/queries/text_query.rb","lineNumber":9,"sourceCode":"# frozen_string_literal: true\n\nmodule Capybara\n  # @api private\n  module Queries\n    class TextQuery < BaseQuery\n      def initialize(type = nil, expected_text, session_options:, **options) # rubocop:disable Style/OptionalArguments\n        @type = type.nil? ? default_type : type\n        raise ArgumentError, \"#{@type} is not a valid type for a text query\" unless valid_types.include?(@type)\n\n        @options = options\n        super(@options)\n        self.session_options = session_options\n\n        if expected_text.nil? && !exact?\n          warn 'Checking for expected text of nil is confusing and/or pointless since it will always match. ' \\\n               \"Please specify a string or regexp instead. #{Capybara::Helpers.filter_backtrace(caller)}\"\n        end\n\n        @expected_text = expected_text.is_a?(Regexp) ? expected_text : expected_text.to_s\n\n        @search_regexp = Capybara::Helpers.to_regexp(@expected_text, exact: exact?)\n\n        assert_valid_keys\n      end\n\n      def resolve_for(node)","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/queries/text_query.rb#L1-L27","documentation":"Capybara::Queries::TextQuery validates its first (type) argument on construction. Only :all and :visible are valid (valid_types in lib/capybara/queries/text_query.rb:94-96): :visible checks only rendered/visible text, :all checks the entire text including hidden elements. When nil is passed, the type defaults based on Capybara.ignore_hidden_elements / Capybara.visible_text_only. Any other symbol (commonly :invisible, :hidden, or :obscured) raises ArgumentError immediately.","triggerScenarios":"page.assert_text(:invisible, 'Deleted'); expect(page).to have_text(:hidden, 'foo'); page.assert_no_text(:obscured, 'x'); have_content(:all? ...) with a typo'd symbol - all construct a TextQuery whose first symbol is not :all or :visible.","commonSituations":"Developers assuming a CSS-visibility vocabulary (:hidden/:invisible from Capybara's :visible option on finders, or jQuery) applies to text queries too; upgrading old code that used the pre-2.x boolean/other type names; passing a variable for visibility that happens to hold :none or true instead of a symbol.","solutions":["Use :visible (only visible text) or :all (visible plus hidden text) - e.g. expect(page).to have_text(:all, 'foo') replaces a guessed :invisible.","If you were trying to assert text is NOT displayed, use the positive check on visible text: expect(page).to have_no_text('foo') or to have_text(:all, ...) contrast.","Pass no type at all and let the default (from Capybara.ignore_hidden_elements) apply; configure that global instead of per-call types.","Check for typos in interpolated type variables before the call, since any non-:all/:visible symbol fails."],"exampleFix":"# before\nexpect(page).to have_text(:hidden, 'Beta notice')\n\n# after\nexpect(page).to have_text(:all, 'Beta notice')","handlingStrategy":"validation","validationCode":"type = :all # or :visible\nraise ArgumentError, \"bad text type #{type}\" unless %i[all visible].include?(type)\nexpect(page).to have_text(type, 'foo')","typeGuard":"def valid_text_type?(value)\n  %i[all visible].include?(value)\nend","tryCatchPattern":null,"preventionTips":["Remember only :all and :visible exist for text queries; visibility of elements uses a different vocabulary (:visible/:hidden/:any on finders).","When the type comes from a variable, assert membership before passing it to assert_text/have_text."],"tags":["ruby","capybara","text-query","option-validation"],"backgroundTag":"invalid-option-value","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}