簡體   English   中英

測試時連接firebase模擬器

[英]Connect to firebase emulator during test

您好,我正在使用 firebase 函數開發 API,並且我使用模擬器,但是當我在測試期間嘗試訪問模擬器以測試我的 function 以在 firestor 中添加文檔時遇到問題,它無法正常工作並發送數據直接到firebase

這是一個例子

test("return the created document with its uid", async () => {
      const res = await addDoc<any>("test", { message: "hello" });
      expect(res).toHaveProperty("uid");
    });

它沒有將文檔添加到模擬器,而是直接將其添加到 firebase 中的數據庫

我該怎么做才能改用模擬器?

編輯:我忘了說,如果我通過使用 axios 來測試我的 controller,它可以完美運行並使用模擬器,在這兩種情況下,模擬器都會啟動

當您使用模擬器時,建議您使用demo project [1] 而不是真實項目,該線程 [2] 中解釋了如何操作。

祝你好運。

[1] https://firebase.google.com/docs/emulator-suite/connect_firestore#choose_a_firebase_project [2] 如何設置 Firebase 演示項目

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM