0
我有一些难以理解如何测试函数内我的行为在函数内部的操作:如何测试更新状态
componentDidMount() {
$.ajax(
{
url: this.props.url,
dataType: 'json',
cache: false,
success: function (data) {
if (this.props.url === "./information.json")
this.props.updateInfosAction(data.transport);
else
this.props.updateNotifsAction(data.transport);
}.bind(this),
error: function (xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
}
);
}
这里是我的测试,以确保ComponentDidMount
被称为(它作品):
it('Should call component did mount',() => {
expect(GetInfo.prototype.componentDidMount.calledOnce);
});
但我不知道如何实际测试的行动。