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.

Request for 'done' event

See original GitHub issue

Is there a done event that can be listened to on a scope. I want to test multiple parallel requests where I short-circuit on an error and polling for the isDone method seems like a bad idea.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
andykaiscommented, Jul 10, 2019

For what its worth, I actually reversed this design in my test suite. What I do is create my scoped nock mock, then run my test, and when the test finishes I clear the existing scope. I detailed how I did this in https://github.com/nock/nock/issues/1495, but the basic gist is this:

describe('test with request mocks', () => {
  const mock = new NockMock(...) // this doesnt do anything besides instantiate the class
  before(() => {
    mock.init() // create scope
  })

  after(() => {
    mock.done()
  })

  it('a test', async () => {
    await fetch('https://example.com/url')
  })
})

I am assuming you wanted a done event so you could perform some cleanup, log something, or just determine that your test has ended. Ive found that this design works better and makes more sense. The test itself should determine when the test ends, and you should rely on it to trigger your “I am done now” type events.

2reactions
atishaycommented, Aug 23, 2018

I am looking for an event to add a listener to. Otherwise I need to keep polling nock to know when it is done.

Something like:

scope.addListener('done', () => completeTest());
Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - How to listen for Request complete event? Or how ...
Now I need to do something based on a status of a response object. But I would like to continue in my for...
Read more >
Event follow up email templates - LiveAgent
Send a follow-up email to find out how your event performed. For inspirational words, check out our free event follow-up templates.
Read more >
API - Request | Tedious
An done event is emited for each SQL statement in the SQL batch except variable declarations. For execution of SQL statements within stored...
Read more >
Event System - Guzzle Documentation
All events in Guzzle are managed and emitted by an event emitter. ... example registers event listeners to the before and complete event...
Read more >
Using a Request Object Event Listener - AWS Documentation
The complete event is raised when a service object call has finished, regardless of whether the call results in success or error. Here...
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