이 부분은 github project이고이 부분은 KeyPad.js이라는 간단한 테스트를 작성하려고합니다.스타일이 지정된 구성 요소가있는 Jest themeProvider
이 문제에 대해 열어 본 한 가지 해결책은 주제를 구성 요소로 전달하는 것입니다. 이 솔루션은 효소와 작동하지 않을 것입니다.
내 경우의 문제는 어린이 구성 요소가 ThemeProvider를 통해 테마를 수신하고 모든 테마에 소품을 추가해야하는 테스트 작업을 수행 할 수 있다는 것입니다.
예 :
const tree = renderer.create(
<KeyPad
theme={theme}
cancel={()=> true}
confirm={()=> true}
validation={()=> true}
keyValid={()=>true} />
).toJSON();
expect(tree).toMatchSnapshot();
, 키패드의 렌더링 방법은 다음과 같이 변경 주제로 나는이 솔루션을 같이하지을 사방
render() {
let { displayRule, validation, label, confirm, cancel, theme, keyValid, dateFormat } = this.props
return (
<Container theme={theme}>
<Content theme={theme}>
<Header theme={theme}>
<CancelButton theme={theme} onClick={cancel}>
<MdCancel />
</CancelButton>
<Label>{label}</Label>
<ConfirmButton theme={theme} onClick={() => confirm(this.state.input)} disabled={!validation(this.state.input)}>
<MdCheck />
</ConfirmButton>
</Header>
<Display
theme={theme}
value={this.state.input}
displayRule={displayRule}
dateFormat={dateFormat}
cancel={this.cancelLastInsert} />
<Keys>
{[7, 8, 9, 4, 5, 6, 1, 2, 3, '-', 0, '.'].map(key => (
<Button
theme={theme}
key={`button-${key}`}
theme={theme}
click={(key) => this.handleClick(key) }
value={key}
disabled={!keyValid(this.state.input, key, dateFormat)} />
))}
</Keys>
</Content>
</Container>
)
}
소품 것이다. 아무도 이걸 도와 줄 수 없나요?
감사합니다.
ThemeProvider 대신 모든 구성 요소에서 컨텍스트를 사용 하시겠습니까? StyledComponent와 결합하면 왜 컴포넌트가 더 이상 사실이 아닌지 알 수는 없습니다. 스타일을 재정의 할 수 있습니다. – Pietro
@Pietro 아니 당신이 그것을 가지고있는 방식으로 유지하는 것이 좋습니다. 만약 당신이 ' '을 진정한 반응 성분으로 만들고 싶다면 가장 좋은 해결책이다. –