Jest
一般使用 Enzyme 中的
mounJt
或shallow
方法,将目标组件转化为一个ReactWrapper
对象,并在测试中调用其各种方法:
import Enzyme,{
mount } from 'enzyme';
describe('test ...', function() {
it('should ...', function() {
wrapper = mount(
<MyComp isDisabled={
true} />
);
expect( wrapper.find('input').exists() ).toBeTruthy();
});
});
global api
官方文档中有详细介绍,并且有中文版
Enzyme
是官方测试工具库的封装,它模拟了jQuery的API
三种测试方法
shallow
render
mount
shallow
方法就是官方的shallow rendering的封装。
- 测试
App
的标题。
import {
shallow} from 'enzyme';
describe('Enzyme Shallow', function () {
it('the title should be Todos', function () {
const app = shallow