小编Kev*_*ton的帖子

提交前的react-hook-form验证

我有一个表单(抱歉太长了),用户输入姓名、电子邮件、电话、评论非常简单:

    <form
        className={classes.root}
        data-testid="getting-started-form"
        onSubmit={handleSubmit(onSubmit)}
    >
        <div style={{ width: '400px' }}>
            <div style={{ width: '100%'}}>
                <Controller as={<TextField
                    label="Name"
                    id="name"
                    name="name"
                    type="text"
                    value={name}
                    placeholder="Name"
                    onChange={(e: React.FormEvent<EventTarget>) => {
                        let target = e.target as HTMLInputElement;
                        setName(target.value);
                    }}
                    inputProps={{
                        'data-testid': 'name'
                    }}
                />} name="name" rules={{ required: true }} control={control}
                />
                {errors.name && <span>Name is required</span>}
            </div>
            <div style={{ width: '100%' }}>
                <Controller as={<TextField
                    label="Email"
                    id="email"
                    name="email"
                    type="text"
                    value={email}
                    placeholder="Email"
                    style={{ width: '100%' }}
                    onChange={(e: React.FormEvent<EventTarget>) => {
                        let target = e.target as HTMLInputElement; …
Run Code Online (Sandbox Code Playgroud)

material-ui react-hook-form

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

react-testing-library 中的父节点

我测试的组件呈现出以下内容:

<div>Text<span>span text</span></div>
Run Code Online (Sandbox Code Playgroud)

事实证明,为了测试我拥有的唯一可靠文本是“跨度文本”,但我想获得<div>. 使用 Jest 和 react-testing-library 我可以

await screen.findByText(spanText)
Run Code Online (Sandbox Code Playgroud)

这将返回一个 HTMLElement,但它似乎受到限制,因为我没有任何围绕该元素的上下文。例如,像 parentNode 和 previousSibling 这样的 HTML 方法返回 null 或 undefined。理想情况下,我想获取 parent 的文本内容<div>。知道如何使用 Jest 或 react-testing-library 做到这一点吗?

html jestjs react-testing-library

18
推荐指数
3
解决办法
9697
查看次数

什么是php.ini以及它在CentOS中的位置

我是php的新手.我在我的CentOS 6.2机器上安装了php .我添加了一个扩展名,但是当我安装它时,我收到一条警告,我应该将" extension = mongo.so " 添加到php.ini.I找不到php.ini.就在上面,有一个警告,php_ini没有设置为php.ini位置.所以php甚至都不知道它在哪里.什么是php.ini以及它应该位于何处?

php

15
推荐指数
1
解决办法
8万
查看次数

使用Roslyn获取方法参数

我可以使用以下代码从所有调用特定方法的解决方案中获取列表:

var createCommandList = new List<MethodSymbol>();
INamedTypeSymbol interfaceSymbol = 
   (from p
    in solution.Projects
    select p.GetCompilation().GetTypeByMetadataName(
        "BuySeasons.BsiServices.DataResource.IBsiDataConnection")
    ).FirstOrDefault();
foreach (ISymbol symbol in interfaceSymbol.GetMembers("CreateCommand"))
{
    if (symbol.Kind == CommonSymbolKind.Method
        && symbol is MethodSymbol)
    {
        createCommandList.Add(symbol as MethodSymbol);
    }
}
foreach (MethodSymbol methodSymbol in createCommandList)
{
    foreach (ReferencedSymbol referenceSymbol
        in methodSymbol.FindReferences(solution))
    {
        foreach (ReferenceLocation referenceLocation
            in from l
               in referenceSymbol.Locations
               orderby l.Document.FilePath
               select l)
        {
            if (referenceLocation.Location.GetLineSpan(false)
                    .StartLinePosition.Line ==
                referenceLocation.Location.GetLineSpan(false)
                    .EndLinePosition.Line)
            {
                Debug.WriteLine("{0} {1} at {2} {3}/{4} - {5}",
                    methodSymbol.Name,
                    "(" + String.Join(",", …
Run Code Online (Sandbox Code Playgroud)

.net c# roslyn

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

使用“dotnet dev-certs”工具导出 https 证书失败

我正在尝试使用“dotnet dev-certs”工具导出 https 证书以包含在 Docker 映像中。现在我正在使用:

dotnet dev-certs https -v -ep $(HOME)\.aspnet\https -p <password>
Run Code Online (Sandbox Code Playgroud)

我得到错误:

Exporting the certificate including the private key.
Writing exported certificate to path 'xxx\.aspnet\https'.
Failed writing the certificate to the target path
Exception message: Access to the path 'xxx\.aspnet\https' is denied.
An error ocurred exporting the certificate.
Exception message: Access to the path 'xxx\.aspnet\https' is denied.
There was an error exporting HTTPS developer certificate to a file.
Run Code Online (Sandbox Code Playgroud)

我看到的问题是,无论我提供什么路径来导出证书,我都会收到相同的“访问路径被拒绝”错误。我错过了什么?我知道在很多地方都建议了这个命令。但我似乎无法让它发挥作用。

谢谢你。

dotnet-dev-certs

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

使用 VS Code 删除文件或文件夹

当我打开 VS Code 时,我看到了添加文件或文件夹的选项,但没有看到删除文件或文件夹或重命名的选项。任何提示?

visual-studio-code

7
推荐指数
2
解决办法
3万
查看次数

测试异常-unstable_flushDiscreteUpdates

我有一个使用 Jest 和 React-testing-library 以及 .tsx 测试文件(TypeScript)的测试:

import React from "react";
import { Provider } from 'react-redux';
import { render, screen } from "@testing-library/react";
import Home from "./Home";
describe('Home', () => {
    test("renders Programs without crashing", async () => {
        const storeFake = (state: any) => ({
            default: () => { },
            subscribe: () => { },
            dispatch: () => { },
            getState: () => ({ ...state })
        });
        const store = storeFake({}) as any;
        const { getByAltText } = …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs jestjs create-react-app react-testing-library

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

删除codesandbox.io沙箱

我创建了几个不再使用的沙箱,并且弄乱了我的仪表板。我想删除这些沙箱。如何删除沙箱?

codesandbox

5
推荐指数
2
解决办法
5492
查看次数

从控制台应用程序访问 Azure 应用程序配置

我正在尝试使用简单的控制台应用程序访问应用程序配置。到目前为止我有:

static void Main(string[] args)
{
    IConfiguration config = new ConfigurationBuilder()
              .AddUserSecrets("e7315677-d6aa-41ab-b7cc-8e801a7c8ae9")
              .AddAzureAppConfiguration("ConnectionStrings:AppConfig")
              .Build();
    Console.WriteLine("Hello World!");
}
Run Code Online (Sandbox Code Playgroud)

但抛出异常表明

System.ArgumentException:“连接字符串没有关键字“ConnectionStrings:AppConfig”的值。”

我已将此连接字符串放入 Secrets.json 中,并且我知道它是有效的。我究竟做错了什么?

{
  "ConnectionStrings:AppConfig": "<my connection string>"
}
Run Code Online (Sandbox Code Playgroud)

谢谢。

凯文

app-config .net-core azure-app-configuration

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