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.

how to use this lib with async await?

See original GitHub issue

I’m only getting Network Error from all responses

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

5reactions
onlyweicommented, Mar 23, 2018

Here’s how I’m doing it:

beforeEach(() => moxios.install());
afterEach(() => moxios.uninstall());

it('should work with async/await', async () => {
  makeSomeAxiosRequest();

  await respondWith(whatever);
  assert.equal(something, expectation);
});

function respondWith(response) {
  return new Promise((resolve, reject) => {
    moxios.wait(() => {
      moxios.requests.mostRecent().respondWith({
        status: 200,
        response,
      }).then(resolve, reject);
    });
  });
}
4reactions
createthiscommented, Mar 23, 2018

I’ve since switched to axios-mock-adapter. moxios was unreliable creating “Heisenbugs” in my tests that would happen intermittently. It was also quite a bit slower than axios-mock-adapter, which has been very reliable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use async.js libary with an await? - Stack Overflow
You could try the async-retry library. await retry( async (bail) => { const res = await service.getTransactionResult(txHash).execute(); if ...
Read more >
Using Async/Await with AWS Amplify Libraries for Swift
This article will show you how to use async/await with the Amplify Libraries for Swift and will demonstrate how efficiently you can write ......
Read more >
How to add async/await support to an existing library
Suppose we have an existing library that does some asynchronous operations, but it doesn't follow the async/await pattern.
Read more >
5 Ways to Make HTTP Requests in Node.js using Async/Await
Although you can't use the async/await feature for the HTTP requests made with this library, you could potentially use asynchronous streams ...
Read more >
async function - JavaScript - MDN Web Docs - Mozilla
Note: The await keyword is only valid inside async functions within regular JavaScript code. If you use it outside of an async function's...
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