简体   繁体   English

测试时连接firebase模拟器

[英]Connect to firebase emulator during test

Hi I'm developping an API using firebase functions and I use the emulators but I have a problem when I'm trying to access the emulators during my test to test my function to add a document in firestor it isn't working and it send data directly to firebase您好,我正在使用 firebase 函数开发 API,并且我使用模拟器,但是当我在测试期间尝试访问模拟器以测试我的 function 以在 firestor 中添加文档时遇到问题,它无法正常工作并发送数据直接到firebase

Here is an example这是一个例子

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

Instead of adding the doc to the emulators it add it directly to the database in firebase它没有将文档添加到模拟器,而是直接将其添加到 firebase 中的数据库

How can I do to use the emulator instead?我该怎么做才能改用模拟器?

EDIT: I have forgot to say that if I test by using axios to test my controller it works perfectly and use the emulator and in both case the emulators are started编辑:我忘了说,如果我通过使用 axios 来测试我的 controller,它可以完美运行并使用模拟器,在这两种情况下,模拟器都会启动

When you are using an emulator is recommended to use a demo project [1] instead of a real project, how to do it was explained in this thread[2].当您使用模拟器时,建议您使用demo project [1] 而不是真实项目,该线程 [2] 中解释了如何操作。

Good luck.祝你好运。

[1] https://firebase.google.com/docs/emulator-suite/connect_firestore#choose_a_firebase_project [2] How to setup a Firebase demo project [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