最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论