gpt4 book ai didi

firebase - React Native - 使用 firebase 进行 Jest 测试

转载 作者:行者123 更新时间:2023-11-28 20:37:12 24 4
gpt4 key购买 nike

我是 Firebase 的新手。我读过,边走边做单元测试是件好事。所以这就是我最近一直在努力做的事情。我目前在尝试在使用 Firebase 的类上测试渲染时遇到问题。这是我一直试图修复的以下代码:

import 'react-native';
import React from 'react';
import MainTab from '../../components/MainTab';
import Enzyme from 'enzyme';

import renderer from 'react-test-renderer';

it('renders correctly', () => {
const tree = renderer.create(
<MainTab/>
).toJSON();
expect(tree).toMatchSnapshot();
});

但是,当我尝试从 firebase 获取当前用户的 id 时,我在测试中遇到以下错误: enter image description here

以前有没有人遇到过这个错误?附言如果这真的很空虚,只是想学习,请不要对我太苛刻。

最佳答案

1。 signInWithEmailAndPassword

signInWithEmailAndPassword(email, password) returns firebase.Promise containing non-null firebase.User

Asynchronously signs in using an email and password.

This method will be deprecated and will be updated to resolve with a firebase.auth.UserCredential as is returned in firebase.auth.Auth#signInAndRetrieveDataWithEmailAndPassword.

目前,该方法的实现如下:

firebase.auth().signInWithEmailAndPassword(email, password).then(function(user) {
// user signed in
// - user.displayName
// - user.email
// - user.uid // <---- the user's unique ID
})

2。对于你的情况......

如果您需要测试电子邮件/密码身份验证,我建议您使用 firebase“dev”项目并使用此开发 firebase 项目的用户凭据进行测试。

  • 小心,不要存储您的 UID 用于其他测试!
  • Firebase 尚未提供身份验证测试。

3。 Firebase beta 到 1.0 版本

使用新的 firebase-functions-test 更容易进行单元测试简化编写单元测试的 npm 模块。

查看更多信息:

希望我对您有用!

关于firebase - React Native - 使用 firebase 进行 Jest 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49543408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com