Я использую react
с 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};
`
Мой тест:
it('should render a <header> tag', () => {
const renderedComponent = shallow(<Wrapper />)
expect(renderedComponent.type()).toEqual('header')
})
Jest выдает мне эту ошибку:
<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)
По сути, он выдает ошибку, потому что theme
не определено, поэтому он не может прочитать в нем свойство colors
. Как я могу передать тему моему компоненту?
shallow
из jest, чтобы делать это автоматически. (Источник) - person Dispix   schedule 01.02.2018