Coder Social home page Coder Social logo

Comments (9)

ericbiewener avatar ericbiewener commented on August 17, 2024 1

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.

jasonmit avatar jasonmit commented on August 17, 2024

@isi-gach thanks for letting us know!

  1. What were you upgrading from? Knowing this will help me scope down the bug.
  2. Besides the UnhandledPromiseRejectionWarning warnings, is your test behaving as expected?
  3. 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.

isi-gach avatar isi-gach commented on August 17, 2024

@jasonmit

  1. 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

  1. Besides the UnhandledPromiseRejectionWarning warnings, is your test behaving as expected?

Yes, all the tests pass, the only difference is the warning

  1. 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.

jasonmit avatar jasonmit commented on August 17, 2024

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.

isi-gach avatar isi-gach commented on August 17, 2024

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.

jasonmit avatar jasonmit commented on August 17, 2024

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.

isi-gach avatar isi-gach commented on August 17, 2024

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.

jasonmit avatar jasonmit commented on August 17, 2024

@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.

jasonmit avatar jasonmit commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.