Reputation: 983
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 {
}
}
In the above method am trying to set form data to setuserinputs
which is n depoyClass file
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();
});
When am executing ng test
getting failed. Showing below error
Error: <spyOnProperty> : Property setuserinputs does not have access type set
Usage: spyOnProperty(<object>, <propName>, [accessType])
at <Jasmine>
I have followed below stack link(second answer) How do I spyOn Typescript getters and setters?
Upvotes: 0
Views: 602
Reputation: 1172
Looks like you want to spyOn the component's deploy variable instead.
it('should call fillformdata', () => {
var jsoncontent = { ... };
let response = component.fillformdata();
// Spy on component.deployt
const spiez = spyOn(component.deployt, 'setuserinputs');
deployinput.userinputs = [jsoncontent];
expect(spiez).toHaveBeenCalled();
expect(response).not.toBeNull();
});
Upvotes: 1