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);
});
但我不知道如何實際測試的行動。