Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access placeholder text to validate with jest

I'm trying to access the placeholder text in this form input tag, just to validate that the text is correct:

  <form>
    <input name="form" className="form-classname" placeholder="Text inside placeholder"/>
  </form>

I'm shallow rendering this component, and have tried this, but since this is placeholder and not text, the node is returning an empty string as input (as would be expected).

expect(wrapper.find('.form-classname').at(0).text()).toEqual('Text inside placeholder')

Suggestions on what to try next?

like image 653
N.A Avatar asked Nov 16 '25 01:11

N.A


1 Answers

As of the current version of the testing library, you can now simply use the ByPlaceholderText API to do this: https://testing-library.com/docs/queries/byplaceholdertext/

like image 150
Michael Joseph Avatar answered Nov 17 '25 20:11

Michael Joseph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!