【发布时间】:2017-02-09 16:25:09
【问题描述】:
我有以下情况:
describe('API - Input component', () => {
describe('Input element', () => {
it('should have a modifier to its class if data entered is erroneous', () => {
const wrapper = shallow(<Input error="Invalid data" />);
expect(wrapper.find('input').props().className).toBe('form-field__input form-field__input--error');
});
});
});
这工作得很好。只要我将一些数据传递给我的 error 道具,就应该期望一个修饰符类并且测试通过。
现在,我想实现相同的目标,但使用设置功能。像这样:
function setup () {
const props = {
error: {}
};
return shallow(<Input {...props} />);
}
describe('API - Input component', () => {
describe('Input element', () => {
it('should have a modifier to its class if data entered is erroneous', () => {
const wrapper = setup(how do I pass my props here?!);
expect(wrapper.find('input').props().className).toBe('form-field__input form-field__input--error');
});
});
});
谢谢!
【问题讨论】:
标签: unit-testing reactjs mocha.js enzyme