我在React Component中使用AXIOS尝试了ajax调用,如下所示,
expect(axios).toBeCalledWith({
type: 'POST',
baseURL: '/login',
data: JSON.stringify(dataParams),
headers: {
"Content-Type": 'application/json; charset=utf-8'
}
});
当我尝试在JEST中模拟上面的组件时,React组件工作正常。
我已附上下面的JEST代码,
- TypeError: Cannot read property 'baseURL' of undefined
at Axios.request (node_modules\axios\lib\axios.js:32:13)
当我运行npm jest时,我得到上面组件的以下错误
<form id="demoForm" name="demoForm" [ngFormModel]="demoForm" (submit)="demoForm($event, demoForm)"
method="post" action="" autocomplete="off">
<h3 class="first">Demo</h3>
<p-dropdown [options]="cities" [(ngModel)]="selectedCity"></p-dropdown>
<span *ngIf="!selectedCity"> Required </span>
<button pButton [disabled]="!selectedCity" type="submit" (click)="onclick()" label="Click"></button>
</form>
任何人都可以帮我解决JEST中的上述错误