Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spy.callData -- What's Spy.callData used for?, how to use it? #176

Closed
dancer1325 opened this issue Feb 9, 2025 · 1 comment
Closed

Spy.callData -- What's Spy.callData used for?, how to use it? #176

dancer1325 opened this issue Feb 9, 2025 · 1 comment

Comments

@dancer1325
Copy link

dancer1325 commented Feb 9, 2025

In https://jasmine.github.io/api/edge/Spy.html, you can find

(static) callData
Properties:
...

  • Questions
    • What can it be used for?

    • How to use it?

    • Since it's static, as soon as you create the Spy via any method, it will be ever and ever undefined, invoking or not the spy

      ...
      const spy = jasmine.createSpy('getSomething');
              // 1.1 BEFORE being invoked the spy     
              console.log("BEFORE invoking the spy -- spy.callData ", spy.callData);     // undefined
              
              // 1.2 AFTER invoking the spy    
              spy('arg1', 42);
              spy('arg2');
              console.log("AFTER invoking the spy -- spy.callData ", spy.callData);     //    STILL undefined
      ...
      
    • Only to get detailed information through Spy.calls?

        const spy = jasmine.createSpy('spy');
    
        console.log("BEFORE INVOKING - spy.calls.mostRecent() ", spy.calls.mostRecent());     // undefined
        spy(1, 2, 3);
        spy('a', 'b', 'c');
        console.log("AFTER INVOKING - spy.calls.mostRecent() ", spy.calls.mostRecent());  // current callData
    

Note

  • NOT sure if "issue" is the best way to raise up a question, but I did NOT find another channel or indications
@sgravrock
Copy link
Member

An instance of callData represents a single call to a spy. You can access them through a specific spy's .calls property, as you noticed. callData is used by the spy-related matchers like toHaveBeenCalledWith, and you can also write your own matching logic that uses it.

There isn't actually a static Spy.callData property. I don't know for sure, but my guess is that it was marked up that way in order to get the docs for it to show up in the same place as the Spy docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants