I can't find how to check the CSS of a div in my react component.
You can check inline styles (How can I test React component's style with Jest + Enzyme?)
But this doesn't let me check my className='App-header'
of my component.
I have successfully added chai-jquery
, however I don't know how to get my component to fully load, I only get <body></body
returned.
Answering 1 of 3 will solve my problem:
1. How can I test/check the class CSS of my div that I find using expect(wrapper.find('#id'))...
without having the <div>
's CSS as an inline style.
2. How can I make sure my full component renders because right now jquery only returns <body></body>
, but my chai/enzyme returns my full component by using shallow(<App />)
?
3. Is there a way to test CSS style sheets? MAybe this is a workaround.
.
it('should have a header with display: block', (done)=>{
const wrapper = shallow(<App />);
const body = $('body')
console.log(body) // Returns <body></body>
expect(body).exist; // Returns true
expect(body).to.have.css('display', 'block'); //nothing in body, doesn't work
expect(wrapper.find('#body').get(0).props).to.have.property({display: 'block'}) //not in the props because CSS comes from className
done()
})
References:
Failed attempt using assert (how to test showing an element after a click?)
Great Ideas but require inline styles (How to test style for a React component attribute with Enzyme)