【发布时间】:2020-12-14 04:17:56
【问题描述】:
component.ts
fillformdata(): void {
if (this.mark === false) {
var jsoncontent = {
ipaddr: (this.noip == false) ? this.ipinput : this.ipadd,
host: (this.noip == false) ? this.hostinput : this.host,
username: this.usernamevalue,
password: this.passwordvalue
};
this.deployt.setuserinputs(jsoncontent);
} else {
}
}
在上述方法中,我尝试将表单数据设置为setuserinputs,这是 n depoyClass 文件
component.spec.ts
it('should call fillformdata', () => {
var jsoncontent = {
ipadd:"127.0.0.1",
host:"host1",
username:"admin",
password:"admin"
};
let response = component.fillformdata();
const deploy = new deploymentdetails();
const spiez = spyOnProperty(deploy, 'setuserinputs', 'set');
deployinput.userinputs = [jsoncontent];
expect(spiez).toHaveBeenCalled();
expect(response).not.toBeNull();
});
当我执行ng test 失败时。显示以下错误
Error: <spyOnProperty> : Property setuserinputs does not have access type set
Usage: spyOnProperty(<object>, <propName>, [accessType])
at <Jasmine>
我关注了下面的堆栈链接(第二个答案) How do I spyOn Typescript getters and setters?
【问题讨论】:
-
能否在此处提供您的 ts 和 spec.ts 文件,方便查找解决方案。
-
this.deployt是什么?请提供代码。
标签: angular typescript jasmine angular-test