我想模拟整个点击不仅仅是
document.getElementsByClassName()[0].click();
Run Code Online (Sandbox Code Playgroud)
我怎么做?搜索结果似乎都是关于处理此类事件,而不是触发它们.
https://github.com/JedWatson/react-select
我想使用React-Select react组件,但我需要添加测试.
我已经尝试了谷歌发现的几个选项,但似乎没有任何效果.我有下面的代码,但它不会导致更改事件.我已经能够添加一个焦点事件,它增加了'is-focusedsed'类,但'is-open'类仍然缺失.
我用过:https://github.com/JedWatson/react-select/blob/master/test/Select-test.js作为参考
我曾尝试仅在输入字段上使用更改事件,但这也没有帮助.我注意到有一个onInputChange={this.change}选择.
测试
import Home from '../../src/components/home';
import { mount } from 'enzyme'
describe('Home', () => {
it("renders home", () => {
const component = mount(<Home/>);
// default class on .Select div
// "Select foobar Select--single is-searchable"
const select = component.find('.Select');
// After focus event
// "Select foobar Select--single is-searchable is-focussed"
// missing is-open
TestUtils.Simulate.focus(select.find('input'));
//this is not working
TestUtils.Simulate.keyDown(select.find('.Select-control'), { keyCode: 40, key: 'ArrowDown' });
TestUtils.Simulate.keyDown(select.find('.Select-control'), { keyCode: 13, …Run Code Online (Sandbox Code Playgroud) greasemonkey ×1
javascript ×1
mocha.js ×1
mouseevent ×1
react-select ×1
reactjs ×1
tampermonkey ×1
testing ×1
userscripts ×1