Enzyme 介绍
Enzyme 来自 airbnb 公司,是一个用于 React 的 JavaScript 测试工具,方便你判断、操纵和历遍 React Components
输出。
Enzyme 的 API 通过模仿 jQuery 的 API ,使得 DOM 操作和历遍很灵活、直观。Enzyme
兼容所有的主要测试运行器和判断库,文档和例子使用 mocha 和
chai。
使用示例:
import { shallow } from 'enzyme';describe('<MyComponent />', () => { it('should render three <Foo /> components', () => { const wrapper = shallow(<MyComponent />); expect(wrapper.find(Foo)).to.have.length(3); }); it('should render an `.icon-star`', () => { const wrapper = shallow(<MyComponent />); expect(wrapper.find('.icon-star')).to.have.length(1); }); it('should render children when passed in', () => { const wrapper = shallow( <MyComponent> <div className="unique" /> </MyComponent> ); expect(wrapper.contains(<div className="unique" />)).to.be.true; }); it('simulates click events', () => { const onButtonClick = sinon.spy(); const wrapper = shallow( <Foo onButtonClick={onButtonClick} /> ); wrapper.find('button').simulate('click'); expect(onButtonClick.calledOnce).to.be.true; });});
Enzyme 官网
https://github.com/airbnb/enzyme
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。