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.

UnhandledPromiseRejectionWarning after upgrade

See original GitHub issue

I’m using the following npm packages

"@pollyjs/adapter-fetch": "^1.0.0",
"@pollyjs/core": "^1.0.0",
 "@pollyjs/persister-fs": "^1.0.0",

If I try to upgrade @pollyjs/core to 1.1.0 or higher I get the following warnings running my tests with Jest:

(node:16928) UnhandledPromiseRejectionWarning: Error: [Polly] [adapter:fetch] Unhandled request: GET http://localhost/api/gas-types/.
(node:16928) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
(node:16928) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:16928) UnhandledPromiseRejectionWarning: Error: [Polly] [adapter:fetch] Unhandled request: GET http://localhost/api/location/.
(node:16928) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .

any ideas how to figure it out why?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

1reaction
ericbiewenercommented, Mar 7, 2019

I find that this issue occurs if my test finishes before the polly request completes (in my use case, I don’t care about the results of the request). I’m using setup-polly-jest and calling polly.flush() in Jest’s afterEach() setup method seems to do the trick:

const { testPath } = global.jasmine;

Object.defineProperty(window, "fetch", { value: fetch, writable: true });
Polly.register(NodeHttpAdapter);
Polly.register(FSPersister);

const ctx = setupPolly({
  adapters: ["node-http"],
  persister: "fs",
  persisterOptions: {
    fs: {
      recordingsDir: path.resolve(testPath, "..", "./__recordings__"),
    },
  },
  matchRequestsBy: {
    headers: false,
    order: false,
  },
});

beforeEach(() => {
  global.polly = ctx.polly;
});

afterEach(async () => {
  await ctx.polly.flush()
});
0reactions
jasonmitcommented, Feb 2, 2020

Closing as the issue is old and awaiting on polly.flush() before your tests end should resolve this for most. If there are edge cases, feel free to open a new issue with clear instructions on how to reproduce.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UnhandledPromiseRejectionWar...
After updating to Angular 9 to 10 and run ng serve -o. I got the following error (node:34728) UnhandledPromiseRejectionWarning: Error: spawn ...
Read more >
Node.js 15 release: Updated handling of rejections, npm 7, N ...
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not...
Read more >
Unhandled Promise Rejection Warning - Node-RED Forum
In terminal I have this error: (node:1946) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by ...
Read more >
Migrate from v4 - Vue CLI
... UnhandledPromiseRejectionWarning: TypeError: The 'compilation' argument must be an instance of Compilation after upgrading, ...
Read more >
Tips for Upgrading Node 12 LTS Quickly and Painlessly
If you see UnhandledPromiseRejectionWarning messages in your logs, then there is a chance that your Node app will crash after the upgrade.
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