angular - "ReferenceError: fetch is not defined", when Jest test imports Firesbase library - Stack Overflow

I have monorepo, which contains Angular applications and libraries. On of the library contains an Angul

I have monorepo, which contains Angular applications and libraries. On of the library contains an Angular FirestoreService to access Firestore database. The application, when started, works by design. On the other hand, any Jest test, which implicitly refers to FirestoreService fails with:

Test suite failed to run

    ReferenceError: fetch is not defined

      1 | import { inject, Inject } from '@angular/core';
      2 | import { FirestoreDoc } from './firestore-doc';
    > 3 | import { collection, Firestore, getDocs, limit, query } from '@angular/fire/firestore';
        | ^
      4 |
      5 | @Inject({ providedIn: 'root' })
      6 | export class FirestoreService {

      at Object.<anonymous> (../../node_modules/firebase/node_modules/@firebase/auth/src/platform_node/index.ts:33:26)
      at Object.<anonymous> (../../node_modules/firebase/node_modules/@firebase/auth/dist/node/index.js:5:12)
      at Object.<anonymous> (../../node_modules/firebase/auth/dist/index.cjs.js:5:12)
      at Object.<anonymous> (../../node_modules/rxfire/auth/index.cjs.js:5:12)
      at Object.<anonymous> (../../node_modules/@angular/fire/fesm2022/angular-fire-auth.mjs:9:80)
      at Object.<anonymous> (../../node_modules/@angular/fire/fesm2022/angular-fire-firestore.mjs:8:31)
      at Object.<anonymous> (../../libs/firestore/src/lib/firestore/firestore.service.ts:3:1)
      at Object.<anonymous> (../../libs/firestore/src/index.ts:1:1)
      at Object.<anonymous> (src/app/nx-welcomeponent.ts:3:1)
      at Object.<anonymous> (src/app/nx-wellcomeponent.spec.ts:2:1)

To be able to reproduce the issue, I created a skeleton project, only with the key elements of this problem. See: If you want to start the application, see: .json#L5

To verify the issue, just run the unit test: ponent.spec.ts

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744710760a4589328.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信