新的测试,所以不是我敢肯定如何处理这个。我的组件中有一个bool prop
,它决定了元素的className
。布尔被设定的形式是否是有效或不显示的div
包含错误消息反应js测试布尔支柱与Jest
<div>
<div className={!this.props.isValid ? 'login__error error' : 'hidden'}>
...
</div>
</div>
如何开玩笑测试此?
在此先感谢
UPDATE: 继@ hemerson - 卡林的答案,这里是我的测试。但不能确定为什么RangeError: Invalid string length
不合格。
describe('Given invalid details the form should display an error',() => {
let component
beforeEach(() => {
component = mount(<Login />)
})
it('should render valid mode',() => {
component.setProps({ isValid: true })
console.log(component.props())
expect(component).toMatchSnapshot()
})
it('should render invalid mode',() => {
component.setProps({ isValid: false })
console.log(component.props())
expect(component).toMatchSnapshot()
})
})
请加你开玩笑代码太 –