Using enzyme, I'm attempting to test the rendered text of a component. The component is a LinkButton
, and it renders out like so:
<a><button to="/projects">See list of all projects</button></a>
I'm not sure how to directly reference the string "See list of all projects". I'm currently testing it as follows:
let { link } = setup({ type: 'Project' })
link = link.shallow()
const text = link.prop('children').props.children.join('')
expect(link.prop('to')).to.eq('/projects')
expect(text).to.eq('See list of all projects')
link
comes from shallow(<NotFoundCard />).find(LinkButton)
.
I've attempted to use link.find('button')
and link.find('a')
but both return 0 nodes.
edit 1
Code for setup
:
const setup = propOverrides => {
const props = Object.assign({
children: null,
type: 'None',
}, propOverrides)
const wrapper = shallow(<NotFoundCard {...props} />)
return {
props,
wrapper,
card: wrapper.find(Card),
title: wrapper.find(CardTitle),
text: wrapper.find(CardText),
link: wrapper.find(LinkButton),
}
}