효소 (마운트 또는 얕은)를 사용하여 className을 사용하는 반응 성분을 테스트 할 때 div 인 경우 제대로 테스트 할 수 있지만 h1에서 작동하도록 할 수는 없습니다 꼬리표.효소가있는 반응 성분 클래스 이름 테스트하기
마운트 또는 얕은 함께 할 수있는이 일부
- 것입니까?
- 내가 누락 된 것이 있습니까?
- 버그입니까?
의견을 보내 주시면 감사하겠습니다.
JSX :
import React from 'react'
export const PageNotFound = ({heading, content, wrapperCSS, headingCSS, contentCSS}) => (
<div className={ wrapperCSS }>
<div className={ contentCSS }>
{ content }
</div>
<h1 className={ headingCSS }>{ heading }</h1>
</div>
)
PageNotFound.propTypes = {
heading: React.PropTypes.string,
content: React.PropTypes.string,
wrapperCSS: React.PropTypes.string,
headingCSS: React.PropTypes.string,
contentCSS: React.PropTypes.string
};
PageNotFound.defaultProps = {
heading: '404',
content: 'Page Not Found',
wrapperCSS: 'wrapper',
headingCSS: 'heading',
contentCSS: 'content'
};
export default PageNotFound
사양 :
import React from 'react'
import { expect } from 'chai'
import { shallow, mount } from 'enzyme'
import PageNotFound from './PageNotFound'
describe('<PageNotFound/>', function() {
let wrapper;
beforeEach(() => {
wrapper = mount(<PageNotFound contentCSS="mycontent" headingCSS="myheader" content="Message" heading="My Title" />);
})
it('Uses heading prop',() => {
expect(wrapper.find('h1').text()).to.eq('My Title')
});
it('Uses headingCSS prop',() => {
console.log(wrapper.html());
expect(wrapper.find('h1.myheader').length).to.eq(1)
});
it('Uses content prop',() => {
expect(wrapper.find('div.mycontent').text()).to.eq('Message')
});
});
테스트 결과 :
공지 클래스 myheader와 H1을 보여줍니다 디버그 로그,하지만 테스트가 발견 제로 요소와 함께 실패 h1.myheader
<PageNotFound/>
✓ Uses heading prop
LOG LOG: '<div class="_2t--u"><h1 class="myheader">My Title</h1><div class="mycontent">Message</div></div>'
✗ Uses headingCSS prop
expected 0 to equal 1
[email protected]:11:24087
[email protected]:14:52974
[email protected]:14:55858
tests.webpack.js:15:17123
tests.webpack.js:14:10442
✓ Uses content prop
덕분에, 나는 스타일이 참조 제거하고 문제가 계속 – stujo