Is this not the correct way to render a react/reflux test with enzyme but without the store, ie, "dumb"
import React from 'react'
import { shallow, render } from 'enzyme'
import { Controls } from '../Controls' // named export
import LoadingSpinner from '../LoadingSpinner'
let wrapper
let loadingFlags = {
controls: true
}
describe('<Controls />', () => {
it('should render only the loading spinner', () => {
wrapper = shallow(<Controls loadingFlags={loadingFlags} />) // this ensures the spinner will show until data is ready
expect(wrapper.length).toEqual(1) // test passes
expect(wrapper.find(LoadingSpinner)).to.have.length(1)
// ^ TypeError: Cannot read property 'have' of undefined
})
})
When I log wrapper.html()
I can see the <img class='spinner' />
is rendered, but enzyme cannot find it as a component. To me, the docs indicate this is exactly what I should be doing. I suppose I could check for a child with that class, but that seems messier than checking for the component itself, eg the class changes within the Spinner component.
Aucun commentaire:
Enregistrer un commentaire