Skip to content

RTK Query lazy query leaves open handles in jest #3509

@DominicGBauer

Description

@DominicGBauer

Note: I'm experiencing a similar issue as found here https://stackoverflow.com/questions/69538390/jest-not-exiting-properly-when-using-rtk-query-uselazyquery-with-reactnative

ISSUE

When I have a component that uses useLazyQuery in jest. I think the caching behaviour causes issues in jest because the the promise does not finish.

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

I have solved it following the example mentioned in the above link:

const api = createApi({
  reducerPath: 'api',
  baseQuery: fetchBaseQuery({
    baseUrl: 'any-base-url',
  }),
  keepUnusedDataFor: process.env.NODE_ENV === 'test' ? 0 : 60, // <- here
  endpoints: () => {
    return {
      // your endpoints
    };
  },
});

Wondering if this is a bug or if this is expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions