小编cse*_*cse的帖子

JestJS - 尝试在 Node JS 测试中模拟 Async Await

我正在尝试将 Jest 用于我的 Node Js 测试(特别是 AWS 的 Lambda),但我很难模拟异步等待功能。

我正在使用 babel-jest 和 jest-cli。下面是我的模块。我正在访问第一个 console.log,但第二个 console.log 返回 undefined 并且我的测试崩溃。

关于如何实现这一点的任何想法?

下面是我的模块:

import {callAnotherFunction} from '../../../utils';

  export const handler = async (event, context, callback) => {

  const {emailAddress, emailType} = event.body;
  console.log("**** GETTING HERE = 1")
  const sub = await callAnotherFunction(emailAddress, emailType);
  console.log("**** Not GETTING HERE = 2", sub) // **returns undefined**

  // do something else here
  callback(null, {success: true, returnValue: sub})

}
Run Code Online (Sandbox Code Playgroud)

我的测试

import testData from '../data.js';
import { handler …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing node.js jestjs aws-lambda

6
推荐指数
2
解决办法
1万
查看次数

React - 本机导航抽屉式导航嵌套导航

目前,在我正在构建的反应本机应用程序中,我有一个包含两个屏幕的抽屉导航器。对于导航,我使用反应导航。 https://reactnavigation.org/docs/intro/

代码如下,

import { DrawerNavigator } from 'react-navigation'
export  default drawernav = DrawerNavigator(
     {
        Login: {Screen: Login},
        Main : {Screen: Main }
     }
) 
Run Code Online (Sandbox Code Playgroud)

虽然登录位于抽屉导航器内,但我希望登录屏幕没有抽屉导航功能,但主屏幕将登录和主屏幕作为抽屉导航器中的两个选项。但是,现在登录屏幕还有抽屉式导航器。有没有办法让登录抽屉式导航功能消失?

react-native react-navigation create-react-native-app

5
推荐指数
1
解决办法
3346
查看次数

Android Studio“预期函数调用‘Button(...)’”

我是 android studio 的新手,我正在尝试制作一个简单的计算器,它接受一个字符串并返回一个值。
问题是,当编写代码来初始化“Button”对象时,它认为我正在尝试调用一个函数。它显示一个错误,内容如下:

Function invocation 'Button(...) expected
Run Code Online (Sandbox Code Playgroud)

但我并不想调用按钮的函数,只是创建一个 Button 对象。

这是我的主要活动文件:

package com.example.myfirstcalc

import android.os.Bundle;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;



class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main)

        Button calcBtn =  (Button) findViewById(R.id.calculateBtn);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/expressionEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="124dp"
        android:ems="10"
        android:hint="Enter an expression"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <Button
        android:id="@+id/calculateBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Calculate"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/expressionEditText"
        app:layout_constraintVertical_bias="0.089" />

    <TextView …
Run Code Online (Sandbox Code Playgroud)

java android kotlin android-studio

2
推荐指数
1
解决办法
8524
查看次数

如何获得内部结构的大小

我正试图获得内部结构的大小,即struct B.但我收到编译错误:

prog.c:在函数'main'中:prog.c:10:53:error:expected')'before':'token printf("%d |%d",sizeof(struct A),sizeof(struct A: :struct B));

以下是我的代码:

#include <stdio.h>

struct A
{
        struct B{};
};

int main() {
    printf("%d | %d", sizeof(struct A), sizeof(struct A::struct B));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

您能否建议我如何在C中实现这一目标?

更新

来自@Jabberwocky的回答解决了我上面的问题.但是如何遵循代码呢.这也可以在这里找到:

#include <stdio.h>

struct A
{
    struct B{};
};

struct B
{};

int main() {
    printf("%d | %d", sizeof(struct A), sizeof(struct B), sizeof(struct A::struct B));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我得到编译错误如下:

prog.c:8:8:错误:重新定义'struct
B'struct B
^
prog.c:5:10:注意:最初在这里定义
struct B {};
^
prog.c:在函数'main'中:
prog.c:12:71:error:expected')'before':'token …

c sizeof

1
推荐指数
1
解决办法
91
查看次数

如何连接具有相同 id 的对象值

我有一个数组:

let ar = [
    {
         uid:1, 
         flat_no: 1
    },
    {
         uid:2,
         flat_no: 2
    },
    {
         uid:1,
         flat_no:3
    }
];
Run Code Online (Sandbox Code Playgroud)

如果uid相同,那么我想删除重复项uid并将其连接起来flat_no。输出数组应该是这样的:

[
     {
         uid:1, 
         flat_no: [1,3]
     },
     {
         uid:2,
         flat_no: 2
     }
];
Run Code Online (Sandbox Code Playgroud)

javascript arrays

1
推荐指数
1
解决办法
690
查看次数

对于循环,r在400万条记录中持续缓慢

我是r的初学者我必须在TIS列中找到一个数字范围并更新另一列.我正在使用下面的代码,但它非常慢.有关如何改进它的任何想法?

table name : data

    for (i in 1:nrow(data)) {
    if (data$TIS[i] > 100)
    data$test[i] <- ">100" 
    else if (data$TIS[i] > 60 & data$TIS[i] <=100)  
    data$test[i] <- "61-100" 
    else if (data$TIS[i] > 48 & data$TIS[i] <=60) 
    data$test[i] <- "49-60" 
    else if (data$TIS[i] > 36 & data$TIS[i] <=48) 
    data$test[i] <- "37-48" 
    else if (data$TIS[i] > 24 & data$TIS[i] <=36) 
    data$test[i] <- "25-36" 
    else if (data$TIS[i] > 12 & data$TIS[i] <=24) 
    data$test[i] <- "13-24" 
    else if (data$TIS[i] > 3 & data$TIS[i] <=12) …
Run Code Online (Sandbox Code Playgroud)

r

0
推荐指数
1
解决办法
65
查看次数