Unit test 记录

188 阅读1分钟

`it('Header 组件 input 内容框 用户输入会跟随变化,()=>{ const wrapper = shallow(

); const inputElem= wrapper.find("[data-test='input']"); const userInput= '今天学习 Jest'; inputElem.simulate('change',{ target :{value:userInput} }), // 面向数据测试 单元测试 expect(wrapper.state('value')).toEqual(userInput);

// 从Dom结构进行测试,重新获取一次input 值 ,属性测试 集成测试 数据发生变化时候检测,所以重新定义变量 const newInputElem = wrapper.find("[data-test='input']"); expect(newInputElem.prop('value').toBe(userInput); }`,