Comments (9)
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()
});
from pollyjs.
@isi-gach thanks for letting us know!
- What were you upgrading from? Knowing this will help me scope down the bug.
- Besides the
UnhandledPromiseRejectionWarning
warnings, is your test behaving as expected? - Can you share your test code or reduce it down to something you can share?
Knowing all of this should help me replicate it and patch it for you.
from pollyjs.
- What were you upgrading from? Knowing this will help me scope down the bug.
I was using version 1.0.0 for adapter-fetch
core
and persister-fs
- Besides the UnhandledPromiseRejectionWarning warnings, is your test behaving as expected?
Yes, all the tests pass, the only difference is the warning
- Can you share your test code or reduce it down to something you can share?
I have been trying to extract the test to a new repository without success. The warning is triggered by the following line:
app.find('Button[content="HOME"]').simulate('click');
Button
is redirecting to the home page using react-router
<Button content="HOME" onClick={() => history.push('/')} />
The warning disappear if I call await polly.flush()
just before to polly.stop()
So it's not blocking me anymore. Maybe would be good to describe that workaround in the polly.js documentation?
from pollyjs.
Thanks for the feedback.
Let me know if you're able to reproduce at any point. In the meantime, I'll continue to think about the issue.
@isi-gach can you post the test itself? Curious what state Polly is in at the time and how it's being configured.
from pollyjs.
here you go:
import React from 'react';
import { mount } from 'enzyme';
import { Polly } from '@pollyjs/core';
import configService from '../../services/configService';
import PortalApp from '../../PortalApp';
describe('No Match page', () => {
const polly = new Polly('NoMatch', { adapters: ['fetch'], persister: 'fs' });
polly.configure({ mode: 'replay' });
polly.server
.get('/config.portal.json')
.intercept((__, res) =>
res.status(200).json({ ENV: 'development', SERVER_URL: 'http://localhost' }),
);
afterAll(() => polly.stop());
it('display NoMatch after calling a bad Url', async () => {
const config = await configService.getConfig();
const app = mount(<PortalApp config={config} />);
await polly.flush();
app.find('Router[history]')
.prop('history')
.push('BadUrl');
app.update();
app.find('Button[content="HOME"]').simulate('click');
expect(window.location.pathname).toBe('/');
// return polly.flush();
});
});
from pollyjs.
I'm still unable to reproduce it, but if you remove the await polly.flush()
and uncomment the return polly.flush()
does the issue still occur?
from pollyjs.
I get a slightly different warning:
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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: 40)
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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: 41)
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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: 42)
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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: 43)(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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: 44)
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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: 45)
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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: 46)
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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(). (reje
ction id: 47)
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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(). (reje
ction id: 48)
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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(). (reje
ction id: 49)
(node:4154) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of null
(node:4154) 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(). (reje
ction id: 50)
maybe this issue could be related?
from pollyjs.
@isi-gach thanks again and sorry for all the back-and-forth.
I'll continue to think about this and try and reproduce on my end. If any future travelers have a reproduction please add to this issue!
from pollyjs.
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.
from pollyjs.
Related Issues (20)
- Project Status HOT 1
- Support React Native
- [Question] ExpressJS + Typescript + Jest: Not able to record tests. HOT 6
- `getRecordings` in API type should be `getRecording`
- NodeAdapter Memory Leaks indicated with jest --detectLeaks
- how to ddecode base64 response body from recording
- [Question]: Not able to replay the recorded requests HOT 2
- Can polly record and replay websockets requests?
- Node's native fetch support HOT 2
- `env` passed to `config/polly.js` is `development` when tests are executed via `ember exam`
- Un-deprecate adapter-fetch for node because the fetch module was added to Node 18 HOT 2
- No support for body as URLSearchParams
- vue3 vite with arraybuffer. missing module buffer HOT 1
- Polly Doesn't 'See' Some Requests when Running in CircleCI HOT 1
- Not able to intercept request and response with node-http HOT 1
- [Vitest] AWS SDK mocking request fail when ignoring headers: TypeError: Cannot delete property 'authorization' of #<Object> HOT 2
- feat: support custom url -> file path in Node File System Persister
- [Question] What is the purpose of the number on the end of the directory names?
- [Bug] Polly replays weird array type from persisted file (replayedData instanceof Array returns false)
- [feature] - Vitest support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pollyjs.