lundi 8 février 2016

Shallow rendering React form inputs with skin-deep

I am testing a component which renders a form, but prefills one of the fields on the basis of part of the url queryString.

I have this working in the browser (the field has its defaultValue set, and displays the value as expected), however when I try to test both that the defaultValue is set, and that input.value is set correctly, the latter reports as undefined.

expect(input[0].props.defaultValue).to.equal(sensorId); // passes
expect(input[0].value).to.equal(sensorId); // "expected undefined to equal ..."

I'm using skin-deep to do the shallow rendering, and teaspoon to access components in the tree:

import $ as "teaspoon";
const input = $(comp).find("input[name=sensorId]");

Aucun commentaire:

Enregistrer un commentaire