Back to Enzyme

`.key() => String`

docs/api/ShallowWrapper/key.md

2.9.1341 B
Original Source

.key() => String

Returns the key value for the node of the current wrapper. It must be a single-node wrapper.

Example

jsx
const wrapper = shallow((
  <ul>
    {['foo', 'bar'].map((s) => <li key={s}>{s}</li>)}
  </ul>
)).find('li');
expect(wrapper.at(0).key()).to.equal('foo');
expect(wrapper.at(1).key()).to.equal('bar');