reactjs – Enzyme Jest window.getSelection()不起作用
发布时间:2020-12-14 01:38:23 所属栏目:Windows 来源:网络整理
导读:如何解决我的情况?以下功能的Jest Enzyme测试返回 TypeError: window.getSelection is not a function 我的代码: _addNewAgent () { window.getSelection().removeAllRanges(); const newAgent = generateNewAgent(); const newDataBase = this.state.agen
|
如何解决我的情况?以下功能的Jest Enzyme测试返回
TypeError: window.getSelection is not a function 我的代码: _addNewAgent () {
window.getSelection().removeAllRanges();
const newAgent = generateNewAgent();
const newDataBase = this.state.agentsDatabase;
newDataBase.push(newAgent);
this.setState({
currentAgentProfile: newAgent,agentsDatabase: newDataBase,infoDisplayContent: 'profile'
});
}
我的测试: import React from 'react';
import { mount } from 'enzyme';
import App from '../containers/App';
const result = mount(
<App />
);
test('add agent',() => {
const agentsList = result.state().agentsDatabase.length;
result.find('#addNewAgent').simulate('click');
expect(result.state().agentsDatabase.length).toBe(agentsList + 1);
expect(result.state().currentAgentProfile)
.toEqual(result.state().agentsDatabase[agentsList]);
expect(result.state().infoDisplayContent).toBe('profile');
});
解决方法
你必须存根window.getSelection().removeAllRanges().我认为这会奏效:
before(() => {
window.getSelection = () => {
return {
removeAllRanges: () => {}
};
})
});
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- Windows – 通过进程ID查找进程名称[已关闭]
- 从Powershell脚本中引用的DLL对App.Config连接字
- windows-7 – 在Alfresco中使用“在Microsoft Of
- 在非Qt应用程序中使用基于Qt的DLL
- 窗口 – 如何获得R中的屏幕分辨率
- opengl-es – 我可以在Windows Phone 8应用程序中
- SBS-2008上的Powershell ActiveDirectory-Module
- .net – UISpy.exe和Inspect.exe有什么区别? (来
- windows-xp – 如何在不打开新命令行窗口的情况下
- windows-server-2003 – 无法连接到Logical Disk
热点阅读
