을 styled-components
으로, jest
enzyme
을 내 테스트에 사용하고 있습니다. theme
styled-components
에서 오류가 계속 발생하는 테마 구성 요소를 테스트하는 데 문제가 있습니다.테마로 효소 렌더링 된 스타일의 구성 요소
내 구성 요소는 다음과 같습니다
const Wrapper = styled.header`
position: fixed;
top: 0;
left: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
height: 64px;
background-color: ${({ theme }) => theme.colors.main.default};
color: ${({ theme }) => theme.colors.main.text};
`
내 시험은 다음과 같습니다 theme
그렇게 정의하기 때문에
<Wrapper /> › should render a <header> tag
TypeError: Cannot read property 'main' of undefined
at Object.<anonymous>._styledComponents2.default.header.theme (app/containers/AppBar/Wrapper.js:13:182)
기본적으로,이 오류가 발생합니다 :
it('should render a <header> tag',() => {
const renderedComponent = shallow(<Wrapper />)
expect(renderedComponent.type()).toEqual('header')
})
농담이 날이 오류를 제공합니다 그 안에 colors
속성을 읽을 수 없습니다. 내 구성 요소에 테마를 전달하려면 어떻게해야합니까?
당신은 당신의 문제에 대한 해결책을 찾았나요 난 테마 어둡고 밝은 테마를 포함하는 객체있어? – rels
이 문제를 해결 했습니까? – DavidWorldpeace
안녕하세요, 오랜 지연에 대해 사과드립니다. 그 동안 농담조 스타일의 구성 요소가 몇 가지 유틸리티로 나왔습니다. 테마로 추천하는 것은 단순히 소품으로 전달하는 것입니다. 당신은 또한 자동으로 그렇게하기 위해 jest에서'shallow' 메쏘드 주위에 래퍼를 만들 수 있습니다. ([Source] (https://github.com/styled-components/jest-styled-components#theming)) – Dispix