question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chain behaviours for the same command/payload

See original GitHub issue

It isn’t unusual in Jest to chain behaviours of a mock, for instance with several sequential calls to mockImplementationOnce. This useful when you want to reproduce some specific behaviour, such as a call succeeding the first time but failing the second time.

I ran into this problem when I was refactoring my code to use this library. I was able to overcome it by refactoring my code a bit and giving each call/responses unique Ids.

I would consider this lower priority since in most cases you should be able to work around it. Still it might help to simplify test code.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
dmattiacommented, Jun 18, 2021

Sure, I do this like:

    const dbMock = mockClient(someClient);

    // The first call should return LastEvaluatedKey, signaling that pagination should happen
    dbMock.send.onFirstCall().resolves({
      Items: [{ pk: { S: 'a' }}],
      LastEvaluatedKey: { pk: { S: 'a'} },
    });

    // The second call is the final call
    dbMock.send.onSecondCall().resolves({
      Items: [{ pk: { S: 'b' }} ] ,
    });
3reactions
m-radzikowskicommented, Mar 6, 2022

It took a moment but is now released in v0.6.2 🎉

See the new resolvesOnce(), rejectsOnce(), and callsFakeOnce() mock functions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ROP Chaining: Return Oriented Programming
The key thing to understand with ROP chaining is the stack layout. In our case, the payload that we send to the vulnerable...
Read more >
Command-and-control servers: The puppet masters that ...
Command -and-control servers, also called C&C or C2, are used by attackers to maintain communications with compromised systems within a target network.
Read more >
7 Stages of Cyber Kill Chain Supplementary Reading
What is delivery? Attacker sends malicious payload to the victim by means such as email, which is only one of the numerous intrusion...
Read more >
Certificate Transparency MDM payload settings for Apple ...
Use the Certificate Transparency payload to control the behaviour of Certificate Transparency enforcement on iPhone, iPad, Mac or Apple TV ...
Read more >
What is OS command injection, and how to prevent it?
This payload uses the nslookup command to cause a DNS lookup for the specified domain. The attacker can monitor for the specified lookup...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found