IONIC7 + Angular + Jest + CosmosDb

Hello everyone, I hope you are doing well. Currently, I am using Jest in an Ionic 7 project with Angular 17. However, I am encountering an issue with Cosmos DB integration using @azure/cosmos as a dependency. When attempting to run test cases for any service that includes a call to Cosmos DB or is related to it, I encounter an error. Surprisingly, when I test components unrelated to Cosmos, everything works perfectly. The error message is as follows:
`

Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.
   import debug from "./debug.js";
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 | import { inject, Injectable } from "@angular/core";
      2 |
    > 3 | import { CosmosClient, Database } from "@azure/cosmos"
        | ^
      4 |
      5 | import { DB_KEY, DB_URI } from "../../../shared/custom-tokens/customs-tokens";
      6 | import { COSMOS_DB } from "../constants/cosmos-db";

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
      at Object.<anonymous> (node_modules/@azure/cosmos/dist/index.js:6:16)
      at Object.<anonymous> (src/app/data-access/cosmosdb/main/main-db-configuration.service.ts:3:1)
      at Object.<anonymous> (src/app/data-access/cosmosdb/collections/odoo/odoo-collection.service.ts:7:1)
      at Object.<anonymous> (src/app/modules/home/service/settings.service.ts:5:1)
      at Object.<anonymous> (src/app/modules/home/components/settings/settings.component.ts:10:1)
      at Object.<anonymous> (src/app/modules/home/components/settings/settings.component.spec.ts:3:1)

`
Can anyone help me guys?..

:pensive: Can anyone help me understand this kind of error? I’ve researched a bunch of things, but none of them seem to work.

Hi @efirst91, Have you found a solution?

I’m having trouble setting up Jest to work with Ionic 8 and Angular 18. I’ve done a lot of research, but nothing has worked for me so far. Can you please share your configurations with me? I would really appreciate it.