我对单元测试非常陌生,所以像模拟模块这样的东西令人困惑.
在native native中,有一个使用firebase数据库的组件,它返回给定ref的数据:
// when the data of the current user is available
userRef.child(user.uid).on('value', snap => {
// check of val() consists data
if (snap.val()) {
let
authUser = snap.val(),
isPatient = authUser.type === "Patient",
// We update the state object so that the component is re-rendered
this.setState({
// the ID of the current user
authUserUID: user.uid,
// the type of the current user (i.e. Doctor or Patient)
authUserType: snap.val().type,
// title of the dashboard based on the current user …Run Code Online (Sandbox Code Playgroud)这个问题在SO中已经提出过很多次了,但是都是指对象数组。
就我而言,我想过滤对象的对象。
假设我有这个对象:
"Users": {
"w14FKo72BieZwbxwUouTpN7UQm02": {
"name": "Naseebullah Ahmadi",
"userType": "Patient",
"writePermission": false
},
"SXMrXfBvexQUXfnVg5WWVwsKjpD2": {
"name": "Levi Yeager",
"userType": "Patient",
"writePermission": false
},
"VoxHFgUEIwRFWg7JTKNXSSoFoMV2": {
"name": "Ernest Kamavuako",
"userType": "Doctor",
"writePermission": true
},
"hFoWuyxv6Vbt8sEKA87T0720tXV2": {
"name": "Karla Stanlee",
"userType": "Doctor",
"writePermission": true
}
}Run Code Online (Sandbox Code Playgroud)
我想过滤这个,这样我就可以得到以下内容:
"UsersCustom": {
"w14FKo72BieZwbxwUouTpN7UQm02": {
"name": "Naseebullah Ahmadi",
"userType": "Patient",
"writePermission": false
},
"SXMrXfBvexQUXfnVg5WWVwsKjpD2": {
"name": "Levi Yeager",
"userType": "Patient",
"writePermission": false
}
}Run Code Online (Sandbox Code Playgroud)
请注意,这个对象“User”实际上非常庞大(超过 1000 个条目),并且每个用户拥有的属性不仅仅是“name”、“userType”和“writePermission”。
我需要过滤用户对象的原因是这样我可以获得只有(Patient …
javascript ×2
filter ×1
firebase ×1
jestjs ×1
json ×1
object ×1
react-native ×1
unit-testing ×1