【发布时间】:2018-02-12 00:15:04
【问题描述】:
我想编写一个测试,删除我的 InputTag 组件中的 material-ui Chip 组件。知道如何实现吗?这是我迄今为止最好的镜头:
import React from 'react';
import InputTag from '../../src/components/InputTag.js';
import renderer from 'react-test-renderer';
import {shallow, mount} from 'enzyme';
import {spy} from 'sinon';
describe('components/InputTag', () => {
it('should call onRquestDelete method', (done) => {
const deleteTag = spy();
const wrapper = mount(
<InputTag
addTag={() => {}}
deleteTag={deleteTag}
changeTag={() => {}}
tags={[{key: "t1", label: "test"}]}
tag=""
/>
);
expect(wrapper.find('Chip')).toHaveLength(1);
spy(wrapper.instance(), 'handleRequestDelete');
wrapper.find('Chip').first().find('DeleteIcon').simulate('click');
expect.assertions(2);
setTimeout(() => {
expect(wrapper.instance().handleRequestDelete.callCount).toEqual(1);
expect(deleteTag.callCount).toEqual(1);
done();
}, 0);
});
}
有问题的行是
wrapper.find('Chip').first().find('DeleteIcon').simulate('click');
如何找到并单击 DeleteIcon 或对应的操作,即 handleDeleteIconClick?
【问题讨论】:
标签: reactjs sinon material-ui enzyme