jeudi 13 septembre 2018

How to test if an input component is readOnly, React/Enzyme

I've designed a component in react that contains an input field that can only ever be set and therefore must be readOnly but can't figure out how to test if this input is readOnly in Enzyme.

I can't find anything about the readOnly attribute but someone had a similar question to Test if an Input is disabled. from this it seems like I'd need to use something like the code below.

test('select button select input must be read only', () => {
    expect(select.find('div').find('div').find('input').hasAttribute('readOnly', 'true').toBeTruthy();
});

However hasAttribute is not recognised on type ShallowWrapper and none of the other methods in the link above translate/work/are recognised.

Just to clarify my input field is below.

<input readOnly={true} type="text" placeholder={selectedOption} />

Has anyone encountered this before? How Would I use Enzyme to test this input is readOnly?

Aucun commentaire:

Enregistrer un commentaire