2

We use spyOn(this,"_new") to track a function call in jasmine. I need to check the children method call in jasmine. My code sample is given below,

Sample code:

function perform(option) {
   this.answer=this.perform._sum(option.a+option.b);
   console.log(this.answer);
}

My question is how to check the this.perform.sum(option.a+option.b) has been called with spyOn() in jasmine JavaScript?

I have tried the below way, but it was not worked as much I expected?

it("If we pass  arguments to the perform method, ensuring that the sum method has been called or not", function(done) {
    spyOn(this,"perform._sum");

    var option={a:10,b:6};

    this.perform(option);
    expect(this.perform._sum).toHaveBeenCalledWith(option.a,option.b);

    done();
});

But above code has not worked. And also, I had posted an issue regarding this npm-jasmine:Issues. The Question details are given below:

how to check children method has been called in jasmine test cases

Can anybody tell me, how to check the children method call in jasmine using spyOn()?

1
  • Could you post the complete reproducible example? It's difficult to follow the this usage - do you have the test in the same file as the code under test?
    – alecxe
    Nov 15, 2017 at 14:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.