我的开玩笑+酶mount()测试遇到了问题.我正在测试一个功能,它可以切换显示组件.
组件之间进行切换:当state.infoDisplayContent = 'mission'一个missionControl部件被安装时,当state.infoDisplayContent = 'profile'-其它组分的步骤:
_modifyAgentStatus () {
const { currentAgentProfile, agentsDatabase } = this.state;
const agentToMod = currentAgentProfile;
if (agentToMod.status === 'Free') {
this.setState({
infoDisplayContent: 'mission'
});
agentToMod.status = 'Waiting';
} else if (agentToMod.status === 'Waiting') {
const locationSelect = document.getElementById('missionLocationSelect');
agentToMod.location = locationSelect[locationSelect.selectedIndex].innerText;
agentToMod.status = 'On Mission';
this.setState({
infoDisplayContent: 'profile'
});
}
}
Run Code Online (Sandbox Code Playgroud)
当我触发这个函数时,一切看起来都很好,这个测试运行良好,测试成功传递了所需的组件:
import React from 'react';
import { mount } from 'enzyme';
import App from '../containers/App';
const …Run Code Online (Sandbox Code Playgroud) 如何解决我的情况?以下功能的Jest + Enzyme测试返回
TypeError: window.getSelection is not a function
Run Code Online (Sandbox Code Playgroud)
我的代码:
_addNewAgent () {
window.getSelection().removeAllRanges();
const newAgent = generateNewAgent();
const newDataBase = this.state.agentsDatabase;
newDataBase.push(newAgent);
this.setState({
currentAgentProfile: newAgent,
agentsDatabase: newDataBase,
infoDisplayContent: 'profile'
});
}
Run Code Online (Sandbox Code Playgroud)
我的测试:
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');
});
Run Code Online (Sandbox Code Playgroud) 伙计们!有没有人
"Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead."
在使用React 15.5.3 "react-transition-group/CSSTransitionGroup"附件时获得.
看起来这个插件使用旧的PropTypes.有人知道如何避免这个加载项的警告吗?