Jest 28 failure: should return an object or a Promise resolving to an object

See original GitHub issue

The following error is being thrown on Jest 28.1.0 due to Jest breaking changes. https://jestjs.io/docs/upgrading-to-jest28#transformer explains the necessary fix.

      `process()` or/and `processAsync()` method of code transformer found at 
      "node_modules/jest-transform-graphql/index.js" 
      should return an object or a Promise resolving to an object. The object 
      must have `code` property with a string of processed code.
      This error may be caused by a breaking change in Jest 28:
      https://jestjs.io/docs/upgrading-to-jest28#transformer
      Code Transformation Documentation:
      https://jestjs.io/docs/code-transformation

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:22
  • Comments:10

github_iconTop GitHub Comments

2reactions
dobesvcommented, Jul 13, 2022

@graphql-tools/jest-transform isn’t quite compatible, and doesn’t allow multiple operations per file.

1reaction
andre-mullercommented, Oct 2, 2022

I was trying to use @graphql-tools/jest-transform but it’s throwing an error when file has multiple operations.

  ● Test suite failed to run

    TypeError: Cannot read properties of undefined (reading 'source')

      36 |  * Used to generate useUseUserProjectsProjectListQuery
      37 |  */
    > 38 | export const USER_PROJECTS_CONNECTION_QUERY = gql`
         |                                                  ^
      39 |   query useUserProjects_ProjectList(
      40 |     $projectFilters: ProjectFilters
      41 |     $listInputs: ListInput

      at ../node_modules/graphql-tag/src/index.ts:127:25
          at Array.forEach (<anonymous>)
      at gql (../node_modules/graphql-tag/src/index.ts:125:8)
      at Object.<anonymous> (src/views/hooks/useUserProjects.tsx:38:50)
      at Object.<anonymous> (src/views/components/UpdateAssigneesDialog/ProjectList.tsx:19:63)
      at Object.<anonymous> (src/views/components/UpdateAssigneesDialog/ProjectReassign.tsx:27:59)
      at Object.<anonymous> (src/views/components/UpdateAssigneesDialog/UpdateAssigneesDialog.tsx:18:63)
      at Object.<anonymous> (src/views/components/UpdateAssigneesDialog/index.ts:9:69)
      at Object.<anonymous> (src/views/components/EditUserDrawer/components/EditUserForm/EditUserForm.tsx:41:69)
      at Object.<anonymous> (src/views/components/EditUserDrawer/components/EditUserForm/EditUserForm.test.tsx:13:60)
      ```
Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid return value: `process()` or/and ` ...
After updating from jest 27 to jest 28.1.0 all tests fail with the following exception: ... should return an object or a Promise...
Read more >
Jest test fails when trying to test an asynchronous function ...
Be aware that an async function always returns a value (a Promise object), so the "usual" expect(() => yourThing()).toThrow() will not work.
Read more >
Testing Asynchronous Code
Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will...
Read more >
Node.js v19.3.0 Documentation
For example, assert.deepEqual() will behave like assert.deepStrictEqual() . In strict assertion mode, error messages for objects display a diff. In legacy ...
Read more >
Promise.all() - JavaScript - MDN Web Docs
Return value · Already fulfilled, if the iterable passed is empty. · Asynchronously fulfilled, when all the promises in the given iterable fulfill ......
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