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.

Reconsider order of operations with regards to replyOnce

See original GitHub issue

Love the library but this one detail is preventing me from adopting it. Consider Jest’s implemention of mockImplementationOnce https://jestjs.io/docs/en/mock-function-api.html#mockfnmockimplementationoncefn

const myMockFn = jest
  .fn()
  .mockImplementationOnce(cb => cb(null, true))
  .mockImplementationOnce(cb => cb(null, false));

myMockFn((err, val) => console.log(val)); // true

myMockFn((err, val) => console.log(val)); // false

So far looks very similar to replyOnce right? This next section is where it differs:

const myMockFn = jest
  .fn(() => 'default')
  .mockImplementationOnce(() => 'first call')
  .mockImplementationOnce(() => 'second call');

// 'first call', 'second call', 'default', 'default'
console.log(myMockFn(), myMockFn(), myMockFn(), myMockFn());

With axios-mock-adapter’s current order of operations the log would be 'default', 'default', 'default', 'default'. Reason being is that replyOnce and reply are kept in the same list and replyOnce handlers are pushed to the end https://github.com/ctimmerm/axios-mock-adapter/blob/master/src/index.js#L213

Adopting this pattern would be a breaking change and require a bit of reorganization in terms of the internal data structures. If you think this fits in with the project I’d be happy to contribute rather than purse a fork

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
slightlytylercommented, Jul 29, 2020

@sanpoChew I’m no longer on the project that needs this so probably not. My fork has changes that match what I originally envisioned which would be a breaking change, not ctimmerm’s proposal. I made a similar proposal for a different tool which has landed now so there are other options if you need something like this API right now in an available library https://github.com/mswjs/msw/issues/128

0reactions
jueinincommented, Dec 14, 2020

any progress on this override topic?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reconsider order of operations with regards to replyOnce
Coming soon: A brand new website interface for an even better experience!
Read more >
When the Judge Gets it Wrong: Motions for Reconsideration ...
A motion for reconsideration is designed to seek review of an order based on the evidence before the court on the initial motion....
Read more >
PISA 2012 Assessment and Analytical Framework
Co-operation and Development (OECD) launched the Programme for International Student Assessment (PISA) in 1997. PISA represents a commitment by governments ...
Read more >
After a Decision is Issued: Motions for Reconsideration
... you are asking the judge to reconsider his/her ruling and change ... has issued the order that you would like to have...
Read more >
Procedures Manual - United States Bankruptcy Court
Review notice regarding Summons and Pretrial Order, click Next. ... to have that order reconsidered, they can file a Motion to Reconsider Order...
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