我正在尝试测试Firebase集合,但出现以下错误:
_firebase.collections.contacts.get.mockResolvedValue is not a function
我正在使用笑话,并且已经尝试使用以下形式:
collections.contacts.get.mockResolvedValue(() => Promise.resolve([]));
collections.contacts.get.mockResolvedValue(Promise.resolve([]);
但没有一个起作用
在test.spec.js上
import { collections } from "@/lib/firebase.js";
jest.mock("@/lib/firebase.js");
collections.contacts.get.mockResolvedValue([]);
@ / lib / firebase.js
import { firebase } from "@firebase/app";
import "@firebase/firestore";
const firebaseApp = firebase.initializeApp({
// my api keys
});
export const db = firebaseApp.firestore();
export const collections = {
contacts: db.collection("contacts")
};
npm的完整输出运行test:unit:
TypeError: _firebase.collections.contacts.get.mockResolvedValue is not a function
有人知道如何解决这个问题吗?