javascript - 为什么通过 cypress-firebase npm 模块登录时 firebase 未定义?
问题描述
我在用着
"cypress-firebase": "^2.0.0",
"firebase-admin": "^9.11.1"
在我的柏树command.js
文件中:
import firebase from "firebase/app";
import "firebase/auth";
import "firebase/database";
import "firebase/firestore";
import { attachCustomCommands } from "cypress-firebase";
const fbConfig = {
}
firebase.initializeApp(fbConfig);
attachCustomCommands({ Cypress, cy, firebase });
当我尝试执行代码时,我面临以下问题:
类型错误
以下错误源自您的测试代码,而不是赛普拉斯:
> 无法读取未定义的属性“initializeApp”
解决方案
在 Firebase SDK v9 中,API 界面更改为使用模块化、可摇树的代码。您看到的几乎所有文档或示例代码都是为需要更新的 v8 或更早版本的 Firebase SDK 编写的。
在此处阅读有关迁移的更多信息。
由于cypress-firebase
尚未更新支持 v9 SDK,因此需要导入兼容 SDK。请注意,兼容性 SDK 已弃用,理想情况下,您应该找到已更新以支持 v9 的软件包。
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/database";
import "firebase/compat/firestore";
import { attachCustomCommands } from "cypress-firebase";
const fbConfig = {
}
firebase.initializeApp(fbConfig);
attachCustomCommands({ Cypress, cy, firebase });
推荐阅读
- mysql - MySql 自联接查询
- angular - 如何在 Ionic 中单击按钮或 Tile 时调用组件(指令)
- reactjs - 更改的样式 onClick 适用于所有 ListItems 而不是单个 ListItems
- android - 使用 Glide 在 Android Recyclerview Imageview 中显示来自 URL 的图像
- sql - SQL Server - 创建在行中具有 2 个最大值的子集表
- navigation - 循环遍历一系列链接会导致导航超时错误 - puppeteer
- react-native - 使用反应导航导航到嵌套屏幕但使用重置/替换操作?
- node.js - Nodejs 无法连接到 Postgresdb 容器
- html - 如何根据框2改变框1的大小?
- java - sql解析器获取sql查询中使用的所有列